Page 1 of 1
Uploading files with forms. Page won't load with large files
Posted: Wed Jan 22, 2003 10:50 am
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.
Posted: Wed Jan 22, 2003 11:12 am
by puckeye
Can you give a URL where we'll see the errors?
Show us the coding behind your upload page.
Posted: Wed Jan 22, 2003 11:24 am
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ї'file']ї'name'];
echo "<BR>";
echo $HTTP_POST_FILESї'file']ї'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.
Posted: Wed Jan 22, 2003 11:56 am
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.
Posted: Wed Jan 22, 2003 12:01 pm
by MattSharp
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.
Posted: Wed Jan 22, 2003 1:10 pm
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.
Posted: Wed Jan 22, 2003 11:23 pm
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?
Posted: Fri Jan 24, 2003 1:47 pm
by puckeye
Hi Matt,
Could you show us both text files? Maybe some sort of compression (or decompression) is applied...
Posted: Mon Feb 10, 2003 11:13 am
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.