1

Why php give to me error of file upload?

<?php

   if($_FILES["filename"]["size"] > 1024*25*1024)
   {
     $message = 'file must be less, than 25 mb';
     exit;
   }

   if(is_uploaded_file($_FILES["filename"]["tmp_name"]))
   {

     move_uploaded_file($_FILES["filename"]["tmp_name"], "share/".$_FILES["filename"]["name"]);

     $message = 'succesfull!';
   } else {
      $message = 'Error upload file';
   }


?>

form with enctype = 'multipart/form-data'

in php.ini i have got

upload_max_file_size: 25 mb Max_post_data = 25mb upload_tmp_dir = /tmp

Why it does not work?

3
  • result is "Error upload file" , why? Commented Jan 23, 2012 at 0:58
  • 2
    Use var_dump($_FILES); instead of pointless Error upload file and see Commented Jan 23, 2012 at 1:01
  • If is_uploaded_file() fails, then PHP doesn't know why the upload failed. It just knows that it did. The only thing I can think of to check is that there is enough space on /tmp. Commented Jan 23, 2012 at 1:16

3 Answers 3

3

If you do a print_r on $_FILES, you will see an error code. The meaning of the error code can be found here:

http://www.php.net/manual/en/features.file-upload.errors.php

Sign up to request clarification or add additional context in comments.

4 Comments

there is no error: array(1) { ["file"]=> array(5) { ["name"]=> string(17) "1326889022150.jpg" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(14) "/tmp/phpvS3WCa" ["error"]=> int(0) ["size"]=> int(35993) } }
The name of your file input is file or filename? If its the former, then change your above code to: $_FILES['file']['tmp_name'] INSTEAD OF $_FILES['filename']['tmp_name']
<div id="form"> <form action = "upload.php" method = "post" enctype = 'multipart/form-data'> Выберите файл: <input type="file" name="file" /><br /><br /> <input type="submit" class="button red" value="Отправить файл на сервер" /> </form>
Use $_FILES['file']['tmp_name']
1

Verify that your php.ini setting looks like this:

upload_max_file_size=25M

Common Errors include:

upload_max_file_size = 0.25M     // Must be an integer

upload_max_file_size = 25M       // No spaces around equal sign

upload_max_file_size=25MB        // Use M not MB

;upload_max_file_size=25M        // Semicolon in front comments out the line.

Restart server after changing php.ini.

Reference: http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes

Comments

0

if your content length is greater then max post size, you should use exception handler or you should put this code to top code.

if ($_SERVER['REQUEST_METHOD']=='POST' && empty($_POST) && isset($_SERVER['CONTENT_TYPE']) && substr($_SERVER['CONTENT_TYPE'],0,19)=='multipart/form-data')
{
    if ($_SERVER['CONTENT_LENGTH']>1024*1024*25)
    {
        $message = 'file must be less, than 25 mb';
                exit;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.