Uploading files with forms. Page won't load with large files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MattSharp
Forum Commoner
Posts: 62
Joined: Wed Apr 24, 2002 2:25 pm

Uploading files with forms. Page won't load with large files

Post by MattSharp »

I am making a file upload script. When I test it using small files, 35 KB or so, the image file uploads but the image is screwed up. So that's problem 1. Problem 2 is that when I try to upload a larger file, like 3.2 MB the page gives me a cannot display error. What is the problem? Is it because php.ini has too small of limits set? Why does the first image not work right? Thanks.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Can you give a URL where we'll see the errors?

Show us the coding behind your upload page.
MattSharp
Forum Commoner
Posts: 62
Joined: Wed Apr 24, 2002 2:25 pm

Post by MattSharp »

I can't give you a URL because the site is password protected. I assume oyu meant the code that the form calls once its submitted:

Code: Select all

$time = time();

$temp_file = $HTTP_POST_FILESї'file']ї'tmp_name'];		// Temporary File name
$company = $HTTP_POST_VARSї'company'];					// Company Name selected from form
$append = $HTTP_POST_VARSї$appendformname];
$group = $HTTP_POST_VARSї$groupformname];
$uploader = $HTTP_POST_VARSї$uploaderformname];
$new_file = $append . '-' . $time;						// The new file name in the incoming directory
$filename = $new_file . '-' . $HTTP_POST_FILESї'file']ї'name'];

echo "$temp_file<BR>";
echo "<BR>";
echo $HTTP_POST_FILES&#1111;'file']&#1111;'name'];
echo "<BR>";
echo $HTTP_POST_FILES&#1111;'file']&#1111;'size'];
echo "<BR>";
echo "Group: $group";
echo "<BR>";

$exec = exec("mv $temp_file $localpath/$group/$filename");
Thats the main block. There is more after it but nothing dealing with the uploaded file, just other form data.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

You might want to use the move_uploaded_file() function (http://www.php.net/manual/en/function.m ... d-file.php) instead of your exec("mv") command.

I'm not sure why the image is "screwed up" because your code looks fine.
MattSharp
Forum Commoner
Posts: 62
Joined: Wed Apr 24, 2002 2:25 pm

Post by MattSharp »

puckeye wrote:You might want to use the move_uploaded_file() function (http://www.php.net/manual/en/function.m ... d-file.php) instead of your exec("mv") command.

I'm not sure why the image is "screwed up" because your code looks fine.
I did use that function. The same results occurs. It;s not just images eitehr. I tried a Word Document and it was 93 KB locally. After upload it was 177 KB and when I tried to open the file it wouldn't open. Once that page loads does that mean the file was uploaded successfully? Cause when I output the size intially, the size it gets from the Form, its the wrong, larger size, not the original one.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Eventhough the problem still occurs I'd still use the move_uploaded_file() function just to be sure it was properly uploaded.

Your problem mystifies me though. I have a good experience of uploading files (mostly images for newspaper articles) and I either didn't have the image upload at all or it as OK.

The filesize difference could be attributed to the difference in OS (if I assume you upload from a Windows platform to a *nix platform am I wrong?)

If you upload plain text files how do they look once they are online? Maybe by comparing 2 text files you will see something different.
MattSharp
Forum Commoner
Posts: 62
Joined: Wed Apr 24, 2002 2:25 pm

Post by MattSharp »

puckeye wrote:The filesize difference could be attributed to the difference in OS (if I assume you upload from a Windows platform to a *nix platform am I wrong?)

If you upload plain text files how do they look once they are online? Maybe by comparing 2 text files you will see something different.
Yea its windows to linux. I tried a plain txt file and it screws up too. Soemone suggested re-installing PHP?
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Hi Matt,

Could you show us both text files? Maybe some sort of compression (or decompression) is applied...
MattSharp
Forum Commoner
Posts: 62
Joined: Wed Apr 24, 2002 2:25 pm

Post by MattSharp »

It turns out that text files are working ok. But images are mega-ly screwed up. I have tested this script on other servers and it works flawlessy, but it will not work on the server I need it to work on. I am completely out of ideas.
Post Reply