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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Large files fail to upload with no error 1

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
0
0
I have a very simple PHP script. Here is its current code:
Code:
<?php
    if (isset($_POST["Submit"])) {
        if ($_FILES["inputfile"]["error"]==0) {
            echo "<PRE>";
            $fp=fopen($_FILES["inputfile"]["tmp_name"],"r");
            $line=0;
            while (!feof($fp)) {
                $buffer=fgets($fp);
                echo str_pad($line++,6,"0",STR_PAD_LEFT) . ": " . $buffer;
            }
            echo "</PRE>";
        } else {
            echo $_FILES["inputfile"]["tmp_name"] . " is not an uploaded file.<BR>\n";
            echo "Original file name: " . $_FILES["inputfile"]["name"] . "<BR>\n";
            echo "Type: " . $_FILES["inputfile"]["type"] . "<BR>\n";
            echo "Size: " . $_FILES["inputfile"]["size"] . "<BR>\n";
            echo "Error: " . $_FILES["inputfile"]["error"] . "<BR>\n";
        }
        exit();
    }
?>
<form enctype="multipart/form-data" action='import.php' method='post'>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type='file' name='inputfile'>
<input type='submit' name='Submit' value='Submit'>
</form>

This code works perfectly for the most part. If I submit a simple text file, the text file appears in the browser with line numbers. If I try to submit a binary file, it looks funny, but it still works. If I try to submit a file that is a little larger than 30k, I get error code 2. I have upload_max_filesize = 20M in php.ini.

If I try to upload a 13M text file, it doesn't work. In fact, the first IF statement returns false and I just get the form back again. The browser is sending a POST (if I hit F5, it asks me to confirm that I want to re-send the data), but NONE of my form variables are being submitted. The script just acts like no post happened at all.

FYI, my intent is to attempt to upload text files as large as 50M and import them into a database. Originally I had the MAX_FILE_SIZE set to 20000000 to match the 20M in the php.ini file so I could upload the 13MB text file.

I can't debug this when I'm getting no errors whatsoever...it just pretends like I didn't even submit anything!

Any suggestions? I'm running php 5.2.6 on IIS 7.0 under Windows Vista. (Yes, I know. Shut up. I fought with this thing for 4 hours last night just to get PHP working at all!)
 
Create a php program with the following in it...

Code:
<?php
echo phpinfo();
?>

Save that in your web root and see if you notice anything. Search for the word "max"...could be max_execution_time, post_max_size, upload_max_filesize, etc.

Mark
 
Oops, after you save it in the web root, browse to it with IE or Firefox.

Mark
 
Yeah, I always keep a phpinfo() script on my server when I'm doing dev work.

The line you're looking for is this one:

post_max_size = 8M.

I bumped that up to 50 and the upload works fine now. Thanks!

The part that bugs me is...why can't PHP at least pop a notice or warning that the max size was exceeded? Why does it just pretend nothing even happened?

Ah, well. That's why we're here.
 
I add this to the top of PHP scripts that require debugging:

Code:
<?php

error_reporting(E_ALL|E_STRICT);

?>

Also if you haven't already, configure you error log setting in php.ini and give the guest web user read/write/modify on the log file.

-a6m1n0

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top