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

Still having probs with file upload

P: n/a
Hi all

Further to my earlier posting and the advice recieved I have now modified my
code but it still doesn't work. I am trying to upload a file from my local PC to
my remote server by using a form.

This is the form

<html>
<head></head>
<body>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="150000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</body>
</html>

and this is the upload.php script to handle the uploaded file

<?php

$uploaddir = 'images/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Error uploading file.\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

I get a success message like this

File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => 1.jpg
[type] => image/pjpeg
[tmp_name] => C:\WINDOWS\TEMP\php8528.tmp
[error] => 0
[size] => 4435
)

)

But when I look in the directory on my server the file is not there. Now pulling
my hair out as this was supposed to be a simple exercise and I've spent 3 days
on it!! Please help me out here!

Regards
Dynamo
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dynamo wrote:
But when I look in the directory on my server the file is not there. Now pulling
my hair out as this was supposed to be a simple exercise and I've spent 3 days
on it!! Please help me out here!


I had this on Windows as well. Seems like you are required to use the
full path when you move_uploaded_file. In your script, you move it to
the images/ dir, this might not work, so move it to getcwd()."images/"
instead and it should work.

Maybe ;)
Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Jul 17 '05 #2

P: n/a
In article <34*************@individual.net>, Roy W. Andersen says...

Dynamo wrote:
But when I look in the directory on my server the file is not there. Now pulling
my hair out as this was supposed to be a simple exercise and I've spent 3 days
on it!! Please help me out here!


I had this on Windows as well. Seems like you are required to use the
full path when you move_uploaded_file. In your script, you move it to
the images/ dir, this might not work, so move it to getcwd()."images/"
instead and it should work.

Maybe ;)
Roy W. Andersen


Thanks for that Roy but it seems like my webhosts are having some gremlins. I
tried all day yesterday trying to get my posted code to work without success and
yet now it works even though I haven't made any changes. Really wierd!!

Regards
Dynamo

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.