Jump to content

php file upload (limit)


westman

Recommended Posts

ok i got an error.... Fatal error: Uncaught exception 'UploadException' with message 'Unknown upload error' in /home/content/31/......./html/...../style/index_core.php:1759 Stack trace: #0 /home/content/31/......../html/...../index.php(3): require() #1 /home/content/31/.........../html/......../index.php(3): require('/home/content/3...') #2 {main} thrown in/home/content/31/............/html/...../style/index_core.php on line 1759 on line 1759 i have.... throw new UploadException($_FILES['file']['error']); what does the error mean? and how do i get it working?

Link to comment
Share on other sites

The message says "Unknown upload error", which means that your exception was passed a code that it wasn't expecting. You should check to see what the code was that it got. That upload exception class isn't going to help if post_max_size was exceeded, you still need to check for an empty file array.

Link to comment
Share on other sites

how?i don't understand mush without a script example. could you pleas give me a error script and tell me where to put it, to find this problem otherwise ill be here 7 more days with the same problem. more info about my script.....in index.php i have this...

<?php require("style/index_core.php");?>

and all my coding is in index_core.php

Link to comment
Share on other sites

could you pleas give me a error script and tell me where to put it, to find this problem otherwise ill be here 7 more days with the same problem.
You'll be here a lot longer than that if you don't learn how to do this yourself. That's what I'm trying to show you. Look at the code you posted in post 16. There's a class called UploadException, and the constructor takes an error code. I linked to the page on the manual that lists all of the upload error codes. The codeToMessage method takes an error code and returns an error message that matches the error code. As you can see in the switch statement, if it doesn't match the code then the message is "Unknown upload error". That's the message you're getting. That means when you do this:
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {//uploading successfully done} else {throw new UploadException($_FILES['file']['error']); }

That $_FILES['file']['error'] is not one of the matching codes. So maybe it would be a good idea if you print that error code out so that you can see exactly what it is. My guess is that it is blank, but it should be easy for you to print that error code and show yourself exactly what it's set to. After you know what the error code is set to, if anything, then you can figure out why. If you want to find out if $_POST or $_FILES are empty, then they are just arrays. If you did a little research about how to check if an array is empty then you'll find plenty of examples. http://www.google.com/search?client=opera&rls=en&q=php+check+if+array+is+empty&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest The point is that you don't need to rely on other people to tell you everything, there is plenty of research you can do on your own. If you don't know how to check if an array is empty then you don't need a specific piece of code where someone gives you the code and tells you exactly where to put it. You're not going to learn anything that way. You learn by doing research, trying things out, and seeing if they work. There's no reason you need to wait hours or days for people to help you when you could be doing this yourself with a little research. I told you that the $_POST and $_FILES arrays will be empty if post_max_size was exceeded, it should be easy for you to figure out how to check if they are empty and add that code to your page. You're not going to get anywhere if all you do is copy and paste code that you didn't write. You need to understand the code if you're going to be able to do anything with it. We're here to help people understand the code, not do everything for you.

  • Like 1
Link to comment
Share on other sites

i understand what you are saying that you help people to understand code. but i do not understand code i understand the logic better and if it took so long to correct a problem in script i will never forget how to do it next time. since the end of the world is in 14 days do you think you could help me never forget my script problem by helping me find it?

Link to comment
Share on other sites

He is helping. Have you even tried the suggestions he made?

Link to comment
Share on other sites

It sounds like it's not empty then. You can use print_r if you want to print the entire array out to look at what is in it:http://www.php.net/manual/en/function.print-r.php

but i do not understand code i understand the logic better
All code is is logic and syntax. If you understand the logic but not the syntax then it sounds like you haven't studied the language. If you're going to write code you need to do that. Someone building a house doesn't just grab a bunch of materials and tools and start putting up walls, you need to learn how to do it first. Don't worry, there's time to do that, the world isn't going anywhere.
Link to comment
Share on other sites

I would use print_r on just $_FILES, to see everything in it. You can do the same with $_POST, or any other array. e.g.:

echo '<pre>';print_r($_POST);print_r($_FILES);echo '</pre>';

the world ends on 21.12.2012i only have 14 days!
Then why does it matter whether or not you get this website working? I say enjoy your last 2 weeks, go travel. See the world while it's still here, get out of Turkey and come to the US. Just don't spend all your money quite yet. I guess the good news is that the fighting in Syria will only last for another 2 weeks.
Link to comment
Share on other sites

That means both arrays are empty, so it sounds like you're hitting the post_max_size. You can use the empty function to check if both arrays are empty, and show an error message if they are that the file was too big. Since both arrays will be empty, you won't be able to use $_POST to tell if the form was submitted. One way to get around that is to use a $_GET parameter in the form action, e.g.: <form action="upload.php?submit" ... Then you can check if $_GET['submit'] is set to determine if the form was submitted. If the form was submitted, but both $_POST and $_FILES are empty, then the file was too big.

Link to comment
Share on other sites

It's too big for the post_max_size limit. If it's too big for the max file upload limit then the $_FILES array will have an error code saying that was the problem. If it's too big for post_max_size then PHP does not populate $_POST or $_FILES.

Link to comment
Share on other sites

then tried to upload a 71MB flv. file and it did not upload and got no errorswhat am i doing wrong?
Do the same checking I've told you to do. Check if $_POST and $_FILES are empty, for example. The same debugging applies regardless of whatever you change the settings to. If you want to verify that the server is using the correct settings, create a phpinfo page and open it, it will have all of the settings that PHP is actually using: <?php phpinfo();
Link to comment
Share on other sites

i just tried... if (empty($_FILES['video_upload'])) {echo 'vid not there!';$updateMsg_upload .= "vid not there!";}else{echo 'vid there!';$updateMsg_upload .= "vid there!";}if (empty($_POST['vid_name'])) {echo 'post not there!';$updateMsg_upload .= "post not there!";}else{echo 'post there!';$updateMsg_upload .= "post there!";}and got no feed back positive or negative.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...