Jump to content

Uploading a big file


Imark

Recommended Posts

When I use the same code to upload a small file, it works fine. But when I select a big file (19 MB *.wmv video), the upload fails. There are no warnings or errors shown, even though I have the "or die" statement on the move_uploaded_file() and mysql_query() function calls.

I tried increasing the "<input type="hidden" name="MAX_FILE_SIZE" value="2000000">" to 2000000000.

I changed to "upload_max_filesize = 25M" in the 3 php.ini's that I found. Didn't help.

 

What else can it be?

 

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td>First name: <input name="fname" type="text"><br></td>
<td>Last name: <input name="lname" type="text"><br></td>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>

<?php

// Insert form values (fname, lname, userfile info)
$uploadDir = "C:\\xampp\\xampp\htdocs\upload\\";

if (isset($_POST['upload'])
    && !empty($_POST['fname'])
    && !empty($_POST['lname'])
    && !empty($_FILES['userfile']['name']))
{

    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    $filePath = $uploadDir . $fileName;
    
    $result = move_uploaded_file($tmpName, $filePath) or die ('File upload failed: ' . mysql_error()) ;
    
    if (!$result)
    {
        echo "Error uploading file";
        exit;
    }

    include 'config.php';
    include 'opendb.php';
    
    if (!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
        $filePath = addslashes($filePath);
    }


    $query = "INSERT INTO med_test (fname, lname, fileName, size, type, link, time)
        VALUES ('$fname', '$lname', '$fileName', '$fileSize', '$fileType', '$filePath', NOW())";

    mysql_query($query) or die ('insert query failed: ' . mysql_error());
    
    include 'closedb.php';
    
    echo "<br> Files uploaded<br>";

}    
else { echo "Must fill in all fields "; }

?>

Link to comment
Share on other sites

The server can time out during the upload. What happens, does it go to a blank screen, or loads forever.  A 25mb file would take roughly 30-45 minutes on average for a php script to upload, that take's time.  4 fairly large images each less than a meg, can take 5 minutes depending.  If not that then most likely the server time'd out.

Link to comment
Share on other sites

This is caused by PHP timing out most likely. You'd need to edit the max_execution_time in your php.ini.

The server can time out during the upload. What happens, does it go to a blank screen, or loads forever.  A 25mb file would take roughly 30-45 minutes on average for a php script to upload, that take's time.  4 fairly large images each less than a meg, can take 5 minutes depending.  If not that then most likely the server time'd out.

It gives the form back, without the confirmation message "file uploaded."

 

The file and the server are on my local machine that I'm using to develop. It shouldn't be taking 60 sec to copy an 18 MB file from one directory to another. And it doesn't give a blank screen (like an unending loop). It shows the form right away.

 

Why are you checking for a mysql error?

I shouldn't be? :-\

Link to comment
Share on other sites

try using the proper form conditions ok

 

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

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.