PHP file upload

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

Threaded View
   *  dumb newbie alert *

Hi, it's me again. This time I'm learning to upload files. I'm using an
HTML form file:

<form method=post action="upload_file.php"
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /><br />
<input type="submit" name="submit" value="Submit" />

which sends the file (in this case, "red.jpg") to the following PHP


if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 20000))

    if ($_FILES["file"]["error"] > 0)
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        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. ";
            "upload/" . $_FILES["file"]["name"]);
            echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    echo "Invalid file";

...and this is the message that appears:

Upload: red.jpg
Type: image/jpeg
Size: 7.0869140625 Kb
Temp file: /tmp/phpu4jlYq
Stored in: upload/red.jpg

so far; sur real...

the problem is, that I can't find my file "red.jpg", or
"upload/red.jpg"-- or even a folder marked "upload/"-- anywhere on my
server. Am I missing something? (well, <i>obviously...</i>)

and [if so] what should I do?

Thanks for your patient assistance.

Re: PHP file upload

rfhurley contained the following:

Quoted text here. Click to load it

Have you created the folder?  Is it writable?  

Easiest way is with an ftp client like WS-FTP with which you can create
the folder and chmod it to be writable.


Geoff Berrow

Re: PHP file upload

rfhurley wrote:
Quoted text here. Click to load it

Yes, you should:
1. Create a directory to which you want to move the uploaded files.
2. Chmod this to 0766 (or 0777).

Also, temporarily enable error reporting (do not do this on a live
environment..) so you can see it if move_uploaded_file fails and how.

(possibly to error_reporting(E_ALL|E_STRICT); if you're in the mood for
cleaning bad habits in code.)
Rik Wasmus

Site Timeline