Jump to content

[SOLVED] File upload


ngreenwood6

Recommended Posts

I know quite a bit about php but I have never done and file uploading. I have created these two files:

 

index.html

<html>
<title>Upload File</title>
<body>

<form enctype="multipart/form-data" action="uploaded.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

</body>
</html>

 

and uploaded.php

<html>
<title>Uploaded File</title>
<body>
<?php

$target_path = "videos/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
   " has been uploaded as a ". basename($_FILES['uploadedfile']['type']) . "";
} else{
   echo "There was an error uploading the file, please try again!";
}
?>

</body>
</html>

 

 

The code is working. However, whenever I try to upload a video using this method it just gives me an index undefined error. I am not sure if it is because of the type or if it is the file size because the file is about 20MB. I can upload smaller files and of a different format.

 

The error is:

 

Notice: Undefined index: uploadedfile in C:\wamp\www\upload\uploaded.php on line 8

 

Notice: Undefined index: uploadedfile in C:\wamp\www\upload\uploaded.php on line 10

There was an error uploading the file, please try again!

 

Any help is appreciated.

 

EDIT: I forgot to mention that I changed the post_max_size in the php.ini file like this: post_max_size = 80000M and upload_max_file_size too.

Link to comment
https://forums.phpfreaks.com/topic/149696-solved-file-upload/
Share on other sites

EDIT: I forgot to mention that I changed the post_max_size in the php.ini file like this: post_max_size = 80000M and upload_max_file_size too.

Yes, but did you stop and start your web server to get any changed made to php.ini to take effect or use a phpinfo(); statement to check what the actual values are?

Link to comment
https://forums.phpfreaks.com/topic/149696-solved-file-upload/#findComment-786086
Share on other sites

@PFMaBiSmAd - Yes I did.

 

@rhodesa - I am now getting this error lol:

 

Notice: Undefined index: uploadedfile in C:\wamp\www\upload\uploaded.php on line 8

 

Notice: Undefined index: uploadedfile in C:\wamp\www\upload\uploaded.php on line 10

There was an error uploading the file, please try again!

Notice: Undefined index: uploadedfile in C:\wamp\www\upload\uploaded.php on line 26

 

Fatal error: Uncaught exception 'Exception' with message 'Unknown error uploading file.' in C:\wamp\www\upload\uploaded.php:34 Stack trace: #0 {main} thrown in C:\wamp\www\upload\uploaded.php on line 34

Link to comment
https://forums.phpfreaks.com/topic/149696-solved-file-upload/#findComment-786096
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.