Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading a big file

Status
Not open for further replies.

EagleM

Programmer
Jan 17, 2007
31
US
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, but it didn't do anything.

Why is it not working with a 19 MB file, when it works fine with a small file?

Code:
<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 "; }

?>
 
check your php.ini for limitations in file sizes.
 
I changed it in php.ini to 25 MB, and it still doesn't work.
Do I need to restart sopmething? What else could it be?

; Maximum allowed size for uploaded files.
upload_max_filesize = 25M
 
you should restart your webserver after changing php.ini (unless you are running php as a cgi).
 
Your web server may have a limit, too. For example, the Apache runtime configuration directive LimitRequestBody can limit the amount that can be uploaded.

If you're running Apache, check httpd.conf for a LimitRequestBody directive. If the directive is not there, then you have no Apache-set limit.


Want the best answers? Ask the best questions! TANSTAAFL!
 
I restarted Apache, but it didn't help.
There is no LimitRequestBody directive in httpd.conf.

I see 3 php.ini files. I changed all 3, restarted Apache, and still nothing.
 
How long is it taking to move these large files? Perhaps you could be running afoul of max_execution_time or max_input_time in php.ini


Want the best answers? Ask the best questions! TANSTAAFL!
 
I don't think it's moving them at all. When I click on Submit, it just gives me the form again.
The file is about 18MB and it's on the same machine, so it can't take more than the 60 seconds.

Is it supposed to give an error message?
 
try this code as a debug test

Code:
<?php
session_name("Tek-Tips Test");
session_start();
if (isset($_POST['submit'])) {
  $_SESSION['uploads'][] = $_FILES;
  echo "<pre>".print_r($_SESSION['uploads'], true)."</pre><hr/><br/>";
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" encoding="">
<input type="file" name="uploadFile" /><br/>
<input type="submit" name="submit" value="Test Upload" />
</form>

try with different file sizes and see whether it breaks at all. when you have tried a few upload the results of the cumulative print out to the forum.
 
sorry, forgot the encoding in the form tag.

Code:
encoding="multipart/form-data"
 
For any file that I select, it shows the same thing:
Array
(
[0] => Array
(
)

)

Doesn't look right..
 
nope, that's not right. you will always get the files superglobal populated for every uploaded file.

so ... looks the file does not get to your server.

check max_input_time in your php.ini
check that file_uploads is turned on in php.ini (unlikely to be the problem as you say you can upload small files).

derive the actual php.ini file you are using by running the command phpinfo()
 
It must be something else. max_input_time is set to 60 sec. by default, and all the files are on the same machine.
 
can you try this code instead (slight tweak to the previous debug)
Code:
<?php
session_name("Tek-Tips Test");
session_start();
if (isset($_POST['submit'])) {
  $_SESSION['uploads'][] = $_FILES;
  echo "<pre>".print_r($_SESSION['uploads'], true)."</pre><hr/><br/>";
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" encoding="">
<input type="file" name="uploadFile" /><br/>
<input type="submit" name="submit" value="Test Upload" />
</form>
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top