/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] File Upload or Delete with Database Entries?

Ok, so here’s what I’ve got (more or less) for the file-upload form:

[code=html]
<tr>
<td><input type=”text” name=”title_new” /></td>
<td colspan=”2″><input name=”file_new” type=”file” class=”file” /></td>
<td><select name=”category_new”>
<option value=”1″>Category 1</option>
<option value=”2″>Category 2</option>
<option value=”3″>Category 3</option>
</select></td>
<td class=”boxed”><input type=”checkbox” name=”show_new” value=”1″ /></td>
<td class=”boxed”><input type=”checkbox” name=”delete_new” value=”please” onClick=”return confirm(‘Are you sure you want to cancel this file upload?’)” /></td>
</tr>[/code]

That’s for the “add new” area… There is also a “delete” checkbox for the list of existing files… pretty much the same as the “cancel” checkbox here.

I cannot seem to get a file-uploader to work… at all.

The target-directory is called “docs” and that folder is sitting in the same directory as this page (so it’s just “docs/” from where I’m at)

I need it to check if filenames already exist and add something to the end of it so the filename is unique…

and I need it to delete files from the server if the delete button is selected for it. I can isolate the one that needs to be removed, I just don’t know how to remove it.

Any help would be greatly appreciated… Feel free to ask questions if you need more clarification. I’m sure my request is as clear as mud.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@criterion9May 02.2012 — Where is the code handling the upload? All I see is a form to allow a user to submit a file, but nothing that handles the copying of the file from the temporary space to the desired directory.
Copy linkTweet thisAlerts:
@amandaNHTauthorMay 02.2012 — That's exactly the problem I'm having... The file-upload part of the form processor doesn't work. I have tried 10 different tutorials but I keep royally screwing it up every time I try to put something together that works. ? I just don't understand PHP file uploads.
Copy linkTweet thisAlerts:
@criterion9May 02.2012 — How about you post the php code you are having trouble with along with any errors you may be encountering so we can see if there is some assistance we could provide?
Copy linkTweet thisAlerts:
@masterwinMay 04.2012 — <?php

if(isset($_REQUEST['submit'])) {

if ((($_FILES["file"]["type"] == "image/gif")

|| ($_
FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg"))

&& ($_
FILES["file"]["size"] < 20000))

{

if ($_FILES["file"]["error"] > 0)

{

echo "Return Code: " . $_
FILES["file"]["error"] . "<br />";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "<br />";

echo "Type: " . $_
FILES["file"]["type"] . "<br />";

echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

echo "Temp file: " . $_
FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}

}

else

{

echo "Invalid file";

}

}

?>

<html>

<body>

<form action="" method="post" enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file" />

<br />

<input type="submit" name="submit" value="Submit" />

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@ibixxonMay 04.2012 — i guess that code is from w3schools. com

If you check their file upload form,

the name of their file input is file
[code=html]
<input type="file" name="file" />
[/code]

that is why they used "file"

in their $_FILES array.

LIKE:

[CODE]
$_FILES['file']
[/CODE]

In this case, the name of your file upload input is file_new
[code=html]<input type="file" name="file_new"/>[/code]
So your code should be something like
[CODE]
$_FILES['file_new']['size']

$_FILES['file_new']['type'] . . .
etc
[/CODE]

hope it helps
×

Success!

Help @amandaNHT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...