By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Uploading a file to my shared-server.

P: 31
Hi all.

I need to make a file uploader, so a client can upload pictures to a directory on their shared server, so that they can later include the photos in news updates.

I simply want to take this form:

[HTML]
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
[/HTML]

and make it upload a file.

my php end looks like this

[PHP]<?

// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>[/PHP]


However, It doesn't work. I tried to see what the error was by doing

[PHP]
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) or die (echo mysql_error());[/PHP]

but that doesn't seem to do anything for me (probably syntax error on my part).

Any idea why this isn't working? If you have an alternative method, please let me know as i just got this from a tutorial site.

thanks in advance.
Sep 28 '07 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

Have you tried turning on the debug messages?
If so, are you getting any errors?

Try echoing the path you are moving your new file to, just to see if it looks like you expect it to.
Sep 29 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.