Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Upload zip file

  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Upload zip file

    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.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 if that's all you want.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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" ?

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you just want to check that the file ends in '.zip', you can do it like this:
    PHP Code:
    $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:
    PHP Code:
    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



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •