Still having probs with file upload

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

<!-- 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" />

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


$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 "</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!


Re: Still having probs with file upload

Dynamo wrote:
Quoted text here. Click to load it

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 / /

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

Re: Still having probs with file upload

Quoted text here. Click to load it

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!!


Site Timeline