Jump to content

File Upload Large Files not working Apache2/PHP5/linux


tln6482

Recommended Posts

I have edited my php.ini file

upload_max_filesize = 1000M
post_max_size = 1000M

The path to the .ini file is /usr/local/lib/php.ini

I am not sure if Apache is reading the file or not, it is able to upload files of about 6-7M or less just fine, but when I do a file roughly 200M it doesn't work. I've been searching around trying different things like a .htaccess file and what not. Nothing has seemed to work so far.

 

Any help is MUCH appreciated!

 

Thank ya much!

 

-T

Link to comment
Share on other sites

Okay, what would be a good size for the memory_limit var?

I have been restarting apache each time, but I don't see anywhere in the httpd.conf reading anything in about php except for the libphp5.so module. Didn't in earlier versions of apache have something pointing to the php.ini file? I almost feel as though it is not reading it at all......

Link to comment
Share on other sites

Umm, it depends on your system for the memory limit. But when files are uploaded they are read into memory and then stored in a temporary file (at least that is my impression). But if your computer only have 512MB of memory on it, well it would be unwise to set it to higher then 384MB imo.

 

So depending on your system, choose wisely. For the 200MB file test, I would set it to 384M and see how that works for you.

Link to comment
Share on other sites

I talked to the network admin and he said 500M should be fine, the server has 2 gigs......

 

What does a phpinfo(); statement show for the two settings you have been trying to change?

 

I made a phpinfo.php and got:

upload_max_filesize 1000M 1000M

post_max_size 1000M 1000M

memory_limit 500M 500M

Link to comment
Share on other sites

Is your problem solved?

 

Nope......still not working.

 

Can the problem really be with my code? Other files get uploaded just fine, but not the larger type which is the primary focus of the project I'm working on.

 

                <label class="description" for="element_1">Upload a Flash File (.flv) </label>                                
                <div>                                                                                                         
                        <input id="element_1" name="file" class="element file" type="file"/>                                  
                </div> <p class="guidelines" id="guide_1"><small>Choose the .flv file that you want to upload to site.</small>
</p>                                                                                                                          
                </li>           <li id="li_2" > 

 

Then the upload php form:

 

<html>
<head><title>File Upload</title></head>
<body>
<?php

// Set target Dir -will be more advanced/modified later
$uploaddir="test/";

// Errors?
if ($_FILES['file']['error'] > 0) {
echo "<h1>There is a problem: </h1>";
switch ($_FILES['file']['error']) {
	case 1: echo "<p>File greater than allowed in html</p>"; break;
	case 2: echo "<p>File greater than allowed in php.ini</p>"; break;
	case 3: echo "<p>File only partially received</p>"; break;
	case 4: echo "<p>No file received</p>"; break;
	}
exit;
}

// Possibly test to ensure formats are proper (future if time permitting)


// Set full path + filename
$upfile = $uploaddir . $_FILES['file']['name'];

// Check the upload
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
if (!move_uploaded_file($_FILES['file']['tmp_name'], $upfile)) {
	echo "<h1>Unable to move file to destination</h1>";
	exit;
	}
}
else {
echo "<h1>There was a problem uploading your file.</h1>";
exit;
}

// File uploaded in $uploaddir
echo "<h1>File Upload Succesful!</h1>";
?>
</body>
</html>

 

 

When it doesnt' work, the error I usually get from my checking is at the //Check the Upload and it fails the if statement and echo's "There was a problem uploading your file"

 

Although, one time this morning I got an error hit at the beginning on case 3: file only partially received..........

 

It's all a big mystery to me, I just started php two days ago and have been trying to work this part out so far........

Link to comment
Share on other sites

The reason for wanting to see the code responsible for the symptoms is to know what it is or is not doing.

 

BTW: The case 1: and case 2: reasons are backward. #1 is The uploaded file exceeds the upload_max_filesize directive in php.ini, and #2 is The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

 

You should probably add the Value: 7 error; Failed to write file to disk, in case the disk if full, a disk error is occurring, or the allocated disk space is being exceeded.

 

Since you are checking for the error element > 0 and processing it as an error, that does not necessarily mean that the error element even exists in those cases where you are getting a failure in the is_uploaded_file().

 

There is a condition where if you exceed the post_max_size setting that the $_FILES array is empty and the error element won't be greater than zero because it is not set at all. There are also times when php seems to ignore settings (they display with the expected value but they are being overridden somehow.)

 

So, my recommendations -

 

A) Put in a test and an error message if the $_FILES array is empty. This should be before the existing code testing $_FILES['file']['error'],

B) Only process the uploaded file if the error element is set and is exactly equal to zero,

C) Develop and debug this on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. If the problem is due to an empty $_FILES array you would have been getting php errors when you attempt to access the non-existent elements.

Link to comment
Share on other sites

You may also need to use set_time_limit and set it to 0 in the script so that it does not time out. The script could just possibly be timing out.

 

The other way, as I stated, is to look into a flash / java uploader.

 

Right after I put that in, and ran it worked perfectly...........so knowing that nothing is for sure, I removed the file from the uploaddir, and tried it once again after completely refreshing my browser and not touching any of my files. As you probably guessed.......the next minute it didn't work.

 

 

A) Put in a test and an error message if the $_FILES array is empty.

........

 

How does the $_FILES var work for this?

A simple

if ($_FILES['file'] == NULL)

probably wouldn't work?

Link to comment
Share on other sites

Yep, thank you that check and test worked.....

After sitting and waiting for awhile, it stopped and I hit my error message before even trying to upload........

Gonna try once more during the composition of this post........

 

In the mean time:

Any ideas as to why this will work like once in a great while but not every time I try? I've checked logs/error_messages and /var/log/messages and /var/log/syslog and haven't gotten anything that would give me a clue to why it's doing/not doing this.

 

 

Link to comment
Share on other sites

Okay, I got this solved a few days ago and remembered I should probably follow up on the thread.

 

I'm not 100% sure what my problem was, but I have a feeling it was because when I was testing, I wasn't necessarily filling in all of the values for the html form.......just rushing though things I guess.

 

Either that, or it had something to do with Safari because I was working on a MacBook that day, and when I and everyone else in the office tried it off a different platform it seemed to work. But I haven't had any problems since I have been filling in all of the fields on my forms with random, juvenile responses (when testing).

 

Ahh to be young and innocent again.......maybe not so innocent LOL!

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.