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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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