Dear user
I write a file upload code in php, the code work's fine but it will upload the file 50kb to 60kb, when i try to upload more then 50kb to 60 kb file then the page stuck on loading.
The problem is why it is not uploading more then 60kb file? is there any fault in my code please check it out..

My form.php code is...

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/bootstrap.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
</head>
<body>
<div class="col-md-6">


<form action="upload.php" method="post" enctype="multipart/form-data">
    <label for="">Item</label><br/>
   <input type="file" name="picture" class="form-control"><br/>

    <label for="">Description</label><br/>
    <textarea name="description" id="" placeholder="Enter Item Description" class="form-control"  cols="50" rows="20"></textarea><br/>

    <input type="submit" name="submit" value="Upload" class="btn btn-success">
</form>
</div>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-2.1.1.min.js"></script>
</body>
</html>

my upload.php code is

<?php

include 'conn.php';
$desc=$_POST['description'];
$image=$_FILES['picture'];
$image_name=$_FILES['picture']['name'];
$placed='uploads/';
if(move_uploaded_file($_FILES['picture']['tmp_name'],$placed.$image_name))
{
    $smt=$conn->prepare("INSERT INTO images(Image_Name,Description,Placed_On)VALUES('".$image_name."','".$desc."','".$placed."')");
    $smt->execute();
    header('location:form.php');

}
else
{
    echo 'error on uploading file';
}
?>

Thanks..

Recommended Answers

All 14 Replies

Did you check upload_max_filesize variable in PHP.INI?

run this. Values of the array are the most commonly used in CMS application.

<?php 

 $server_min = array(
                        'max_execution_time' => 1000, 
                        'max_input_time' => 1000, 
                        'upload_max_filesize' => '200M',
                        'post_max_size' => '200M'

                        );


     function get_php_ini_settings($server_min = array())
     {

         $res = '';
foreach($server_min as $setting => $value){
                    $res .= "$setting  : ".ini_get( $setting )."  ";
                    $res .= ini_get( $setting ) < $value ? '(<font color="red">we recommend '.$value.'</font>)': '<font color="red"> OK </font>';
                    $res .= '<br/>';


            }

            $res .= '<font color="red"><b>!Important Notice!</font></b><br/>You can optionally correct the values of the items in red. To do this, you need to make the adjustments in your php.ini file located at. <font color="red"><b>'. php_ini_loaded_file().'</font></b>';
            return $res;
     }


     echo get_php_ini_settings($server_min);

anything that has red font on it, you need to change the value in php.ini. the location has already been given to you by the script.

restart your apache and you should be able to upload upon php.ini file update.

I try almost every thing, but nothing work's. The main problem curently i don't understand is that why i am not able to upload more then 60kb file and why the page stuck on loading. when the page stuck on loading it can't be stoped until i restart the whole project.
Please any help....

are you getting any PHP Errors? Can you display the error log?

no error's just page are loading....

dear it will display no errors and the page are loading...

ok, can you show your access log?

access log?

If you are allowed only for 60kb. the trick is split the file, if you have 120kb split in to two. then create a php script to merge. then call mergescript.php after all split files upload. everything is possible :D cheers

Sir, That's not the solution because my aim is to upload minimum of 100 MB-500 MB file, so i can't spilt the file in milion part's, Please provide a proper solution...

Check the value of LimitRequestBody in the Apache configuration file, every request larger than this limit will be blocked, PHP will not even reply. After you adjust the value reload Apache, otherwise the change will not apply.

Docs: http://httpd.apache.org/docs/current/mod/core.html#limitrequestbody

By the way: if you check the response headers to the upload request, when hitting the server limits you should receive the 413 - Request entity too large error, so as previously suggested the error and access logs of Apache can be usefuls sources to track down the error.

Thanks for everone, I got the solution,The Probem is my editor, i just run the page directly from localhost insted of using an IDE, and it will upload files..

To upload an image (or any other file), you need to create a form with a file field, and set its method to POST. It's also recommended that you include a hidden field with the name MAX_FILE_SIZE, and set its value to the maximum permitted size (in bytes) of the file to be uploaded. This hidden field must come before the file field. Otherwise it won't work. The following code shows a basic upload form:

<form action="" method="post" enctype="multipart/form-data"
name="uploadImage" id="uploadImage">
<p>
  <input type="hidden" name="MAX_FILE_SIZE" 
    value="<?php echo MAX_FILE_SIZE; ?>" />
  <label for="image">Upload image:</label>
  <input type="file" name="image" id="image" />
</p>
<p>
  <input type="submit" name="upload" id="upload" 
value="Upload" />
</p>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.