Upload Script error - Undefined index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
A7x
Forum Newbie
Posts: 10
Joined: Thu Mar 03, 2011 6:07 am

Upload Script error - Undefined index

Post by A7x »

Hey there! I'm back with another problem. Well I'm currently working on the upload script for my website but it's not working the way I want.
So, when I'm, trying to upload, let's say video/avi with filesize of 100 MB the script returns this error:
Notice: Undefined index: myfile in D:\xampp\htdocs\upload\upload.php on line 3

Notice: Undefined index: myfile in D:\xampp\htdocs\upload\upload.php on line 4

Notice: Undefined index: myfile in D:\xampp\htdocs\upload\upload.php on line 5

Notice: Undefined index: myfile in D:\xampp\htdocs\upload\upload.php on line 6

Notice: Undefined index: myfile in D:\xampp\htdocs\upload\upload.php on line 7
Now, let's say I'm gonna upload the same file format (video/avi) but this time with filesize of 2 MB.. everything works fine.
The same goes for images gif/jpeg and all that stuff what's uploaded instantly.

And when I try to upload 12MB .mov video, script will return aforementioned errors. I'm completely lost, because I don't know why it's working in this way... But it seems that errors display only if uploading process takes more than 2 seconds or so... (I'm pretty sure about it)... I noticed that (: Thank you!

upload.php script:
<?php

$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$tmp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];

if ($error > 0)
{
die("Error uploading file.");
}
else
{
echo "File uploaded: $name<br>";
echo "Type: $type<br>";
echo "Size:".($size/1024)." Kb<br>";
}

?>
html form:
<html>
<form action='upload.php' method='post' enctype='multipart/form-data' >
<input type='file' name='myfile'> <br>
<input type='submit' name='upload' value='Upload'>
</form>
</html>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Upload Script error - Undefined index

Post by social_experiment »

Code: Select all

<html>
<form action='upload.php' method='post' enctype='multipart/form-data' >
<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
<input type='file' name='myfile'> <br>
<input type='submit' name='upload' value='Upload'>
</form>
</html>
You should add the 'MAX_FILE_SIZE' hidden field to your upload form, substituting 102400 for your max file size. I'm not sure which setting it is but there is a setting in the php.ini file which limits uploads to 32 mb by default. Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
A7x
Forum Newbie
Posts: 10
Joined: Thu Mar 03, 2011 6:07 am

Re: Upload Script error - Undefined index

Post by A7x »

I tried to add that hidden field to my html code but didn't work, still the same errors when upload takes more than 2 sec. I'm not really sure because I've changed post_max_size in php.ini to 130M, and upload_max_filesize to 128M ... as i said, there are no problems with files that are instantly uploaded, but when upload takes more than 2 sec those errors are displayed.. i'm confused i dont know where's the problem :( any ideas?
//Everything works fine now... But it's kinda weird because I've restarted my PC and after that my upload script works.. im not sure why...
Post Reply