View Full Version : Zipped files corrupt
pspsully
04-14-2008, 03:31 PM
Hi Guys,
I am using PHP to zip files that i upload to my server, but they are becoming corrupt, well not even so much corrupt as it is changing them all to documents.
I am upload NES Roms, with the .nes extension, i am zipping the using a PEAR class but it is changing the type.
The file is identical, exact same bytes in size but it wont open in my ROM Emulator any more.
I am using the PHP PEAR Class to zip the files as my webserver doesnt have zip enabled in PHP 5.2.5 and they wont re-compile it for me.
Here is the code for creating the Zip File:
// Create instance of Archive_Zip class, and pass the name of our zipfile
$zipfile = New Archive_Zip("monopoly.zip");
// Create a list of files and directories
$list = "Monopoly.nes";
// Create the zip file
$zipfile->create($list);
When i choose Get info on the Files in My MAC, everything is the same accept the icons are different and the Kind has changed, on the zipped file it has changed to "Document" where before it is zipped it says "Unix Executable File".
Any ideas, i can post the whole zip class also if needed
without knowing what the class is doing, it's not easy to help you.
Saying that, you have a comment and a variable name (that look like they might be copied...) that mention a 'list' of things to zip, yet you have a single file...is that maybe meant to be an array?
Something else that might be of use, what do you get if you run the 'file' command (on a command line, i.e. file monopoly.zip
Also, does the zip class work on simple text documents? (from textedit or something that simple, not a word processor). One possible source of confusion for Finder (telling you that it's a "Document") is that word-processors use the zip format for their files (OOffice/NeoOffice does, .docx is to a certain extent).
pspsully
04-14-2008, 06:48 PM
Thanks GJay,
yeah, i got the source code from a Tutorial found Here (http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/)
The class im using is very big so i wont display it but here's the download link: http://http://pear.php.net/package/Archive_Zip
Yes, you are correct, it was supposed to be an array but i changed it to a single file as thats all i need it for, i changed it back to an array but i still get the same problem.
If i use it with document files it works fine.
If i open Terminal and use the file command with the zipped rom from php i get the following:
Monopoly.nes: iNES ROM dump, 8x16k PRG, 16x8k CHR, [Horiz.]
Which is the exact same thing i get when i use the command on the original file.
Something else ive just noticed is when i upload the file via my html form, i get php to echo some information about it:
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"]) . " Bytes<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
If i upload a zip file the Type will display "application/zip" but with the .nes files it displays nothing, just blank.
Any insights?? All help is greatly appreciated.
I meant run 'file' on the resulting "zip"
pspsully
04-14-2008, 08:24 PM
Hi GJay,
monopoly.zip: Zip archive data, at least v2.0 to extract
Thats what i get on the zip file.
Is it something to do with PHP not knowing the file type??
it's a valid zip file then.
And I'm completely confused about what your actual problem is. You have a file, you're zipping it, and getting a zip file. Explain the bit that's wrong, as clearly and concisely as possible.
pspsully
04-15-2008, 10:58 AM
Hi GJay,
Im confused too, i know it should work, buts its not.
Ok, i have my Monopoly.nes file, i play it in my nes emulator and it works fine. If i get more info on the file it has the following properties:
Kind: Unix Executable File
Size: 260 KB on disk (262,160 bytes)
and it has a black terminal icon with exec in the top left.
Now, when i upload the file via php, i zip it into a file called monopoly.zip and move that to the nes directory of the site, which all works fine, however, if i download this zip file to my computer and unzip it, the Monopoly.nes file it extracts has these properties:
Kind: Document
Size: 260 KB on disk (262,160 bytes)
and the icon just changes to all white, instead of the black terminal one with exec in the top left.
The size stays the same so the file seems to be ok but when i try to play it in the Emulator it get the error message:
Unable to load ROM image, it may not be a valid ROM image.
I think php does not know what the file type is so it is changing it to a document.
Its really starting to get to me!! Thanks for all the help GJay :)
pspsully
04-15-2008, 12:51 PM
Ok, i have found the Problem.
The problem has nothing to do with the ZIP Class or anthing to do with zipping at all.
When PHP uploads the file it changes the permissions from 755 to 644, when the file is downloaded it stays at 644 and thats why the emulators cant play them.
However, if i use terminal to set the permissions back to 755 on the MAC, it works fine again.
Now, the big problem :)
PHP cant change the permissions of the file, i keep getting an "Operation not permitted" error when i try to chmod the permissions to 755, i get the same thing when i try to chown it.
Im assuming that my hosting company is doing this or am i completly wrong?? I then decided to try the system() route but it doesnt seem to do anything for me, the command im using is:
system("chmod 755 \"Monopoly.nes\" ");
But it doesn't do anything, it doesn't even give an error.
The owner of the file is being changed to "99" also, and i cannot change it to root without the "Operation not permitted" error.
Anyone any ideas??
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.