...

View Full Version : Upload zip file



bfsog
06-26-2005, 08:22 PM
Hey, I wonder if someone could direct me to some code/tutorial on uploading a zip file. This is for a code archive. Once someone signs up to my site they can then upload their own code examples.

Any help would be greatly appreciated.

delinear
06-26-2005, 09:16 PM
Do you want to upload files already zipped or do you mean you want to zip a file after it's uploaded? There are some great pointers on basic file uploading on the php site (http://uk2.php.net/features.file-upload) if that's all you want.

bfsog
06-26-2005, 10:05 PM
I want to upload a zip file that has been zipped on the users computer.

I do not need all the code as I have some simple code that uploads an image, I just am unsure how to specify I only want to upload zip files..?

Fou-Lu
06-27-2005, 03:13 AM
It depends on what you are doing to validate the files. Extension is of course a .zip file. Mime type is application/zip. Without viewing your current code, I cannot suggest what you need to do to alter it.

bfsog
06-27-2005, 08:26 AM
Okay thanks for the input. I have enough to go on now, but just one more thing.

How would an if statement look if I was checking the extension for ".zip" ?

delinear
06-27-2005, 09:06 AM
If you just want to check that the file ends in '.zip', you can do it like this:

$blah = end(explode('.', $_FILES['userfile']['name']));
if($blah != 'zip') {
echo 'The file must be in .zip format!';
} else {
// the file is a zip, carry on with processing the upload
}
As Fou-Lu said, if you want to check the MIME type of the file you can test for application/zip:

if($_FILES['userfile']['type'] != 'application/zip') {
echo 'The file must be a zip file!';
} else {
// the file is a zip, carry on with processing the upload
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum