PDA

View Full Version : Upload image help!


AlexLee
February 5th, 2005, 02:41 PM
Hi, I am using this code to upload my images.

<?php
$file_realname = trim($_FILES['userfile']['name']);
$uploaddir = "images/";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $file_realname))
{
echo $file_realname." has been uploaded";
}
else
{
echo "<strong>$file_realname</strong> did not upload!";
}
?>

And I get this kind of error when I tries to upload a big file.


Notice: Undefined index: userfile in C:\Program Files\Apache Group\Apache2\htdocs\FYP\upload\upload.php on line 2

Notice: Undefined index: userfile in C:\Program Files\Apache Group\Apache2\htdocs\FYP\upload\upload.php on line 5
did not upload!

I set the max file size to be 1mb both in the form and php.ini. The code catches the error saying file did not upload all the way until 10mb and the error occurs. How can I prevent this?

And how do I change the filename of the file after uploaded? I tried renaming in the code but the extension is always goone. How do I retain the extension but change the filename?

degsy
February 5th, 2005, 04:06 PM
Hi,

First I would recommend you try one of these scripts
http://www.zachwhite.com/scripts.htm

See if they work ok for you.
If you still have problems please post back.