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

PHP file upload

P: n/a
* 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"
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>

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

<?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 />";
}
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";
}
?>

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

Jan 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Message-ID: <11**********************@11g2000cwr.googlegroups. comfrom
rfhurley contained the following:
>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>)
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.

--
Regards,

Geoff Berrow
Jan 19 '07 #2

P: n/a
Rik
rfhurley wrote:
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
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>)
Yes, you should:
1. Create a directory to which you want to move the uploaded files.
2. Chmod this to 0766 (or 0777).
3.
move_uploaded_file($_FILES["file"]["tmp_name"],'/the/path/you/chose/'.$_FIL
ES["file"]["name"]);

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.
<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
?>

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

This discussion thread is closed

Replies have been disabled for this discussion.