php move uploaded file causes file to be corrupt

photondesign
photondesign used Ask the Experts™
on
I am uploading a file using php move_uploaded_file on apache 2.2 with php 5.3 on Windows SBS2003
It is an XML file.  When I read it on the server the XML is not valid.  It is valid before I upload it, and if I simply manually FTP the file to the site it works fine.  
The max execution, max file size, max post data, etc have all had their limits increased.
Also, the file does load it is just corrupt, although it reads fine in ultraedit.
I need to get file uploads working asap, please help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012

Commented:
Does it read ok in xml notepad?
Sounds like its the file format that has changed..?

Author

Commented:
if I open it in internet explorer then it is invalid.  Almost as if it is truncated.  If I open in notepad (normal windows notepad) it is all there.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
The upload also corrupts other files including images.
Small plain text files upload without issue.

It is the case for move uploaded file and using PHP ftp functions.  Somehow it seems like the $_FILES array gets corrupted.

Author

Commented:
I have increased the points for this question.
Sorry didn't post this earlier I forgot about this thread altogether.

Also it is not about the points for most of us, sometimes we loose interest in a topic for awhile if we run out of ideas. But thanks for bumping up this thread anyway it just gave me an idea.

Sounds like there is some issue with the data uploading form maybe. Are you using multipart data? http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

You say it looks fine in notepad and then you say it might be truncated when you look at it in IE? Can you explain this abit? If you think its truncated in IE then it appears normal in notepad how does that make sense :S
eg:

 <FORM action="http://server.com/cgi/handle" enctype="multipart/form-data" method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   What files are you sending? <INPUT type="file" name="files"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

Open in new window

Author

Commented:
I am using multi-part form data.  I think I confused things a bit with the showing fine in notepad.  The data is there but not as valid XML, there are bits missing.  I just meant it does reach the end of the file and it is not due to a file size limit.
When an image is uploaded, you will get corruption in the image.
I am perplexed... I really have no idea what might be causing the issues for you. Have you tried the two fixes on this page? http://www.justskins.com/forums/uploading-binary-files-getting-corrupt-98491.html It might be a charset issue :S

Author

Commented:
I have seen that page also, I thought it might be a charset issue.  I haven't got SetOutputFilter PHP
SetInputFilter PHP in the apache conf file anyway.  If I was to use the CharsetDisable On line where should it go?  I have only got one site running on apache.
make a ".htaccess" file yes thats a .htaccess, nothing infront of the .

Then open it with notepad and put this into it : (the code snippet)

Save the file and upload it with FTP onto the folder where your upload script is.
<Files ScriptThatReceivesUploads.php>
CharsetDisable On
</Files>

Open in new window

Author

Commented:
No still got the same corruption.
You should post your receiving php script and your sending html form here so someone with more knowledge can respond to this issue. I hope someone else comes along cos I am stumped. Maybe seeing the source code will give more ideas for me

Author

Commented:
I have gone back to the complete basics and it still doesn't work.
I am wondering whether there is a Apache/PHP/Win2K3 bug, it used to work before I upgraded to the latest stable release of apache and php.  
I needed to upgrade for other issues though, and can't go back.
upload-script.php
upload-test.php

Author

Commented:
I have tried having the form as html rather than php, to see if even that was causing an issue.
Your PHP files look good! I still dont understand this issue. Hmmmm are you using stable versions of PHP and apache? So there is no option to roll back to a previous stable version is there... I really hope someone else replies here. I am sorry photondesign I dont know what is going on

Author

Commented:
I know, everything seems perfect.  As I said all as I can think of is an actual bug as it worked before the upgrade.  If not a bug it has to be a configuration issue.  Unfortunately, there is no roll back possible either.
I am using the stable releases as well.

Thanks for all your suggestions I hope someone else might have some idea.
The situation has never been resolved, I have re-coded the entire system to use imap and an email based upload system.  I think it must be a bug in the PHP version.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial