Jump to content

Upload multiple files into zip archive


amavadia

Recommended Posts

If it was for me that would be fine, but i'm building a system for non technical users and would like to make it as easy for them as possible.

 

It is also useful for me if the function can rename the zip file to keep a consitent naming convention without having to have another database table to relate the zip file to a particular record.

Link to comment
Share on other sites

ok figured this one out by uploading the files and then using zip.lib.php to zip the individual files on the server side, name it how i want and then unlink the individual files.

 

Can someone help with the filetype validation though...

 

foreach ($_FILES as $_key => $_value) {    

    if ($_FILES[$_key]['size'] < 2000000 && 
    ($_FILES[$_key]['type'] == "application/pdf")) {
        print_r($_FILES[$_key]);

    move_uploaded_file($_FILES["$_key"]["tmp_name"],
    "c:/wamp/www/attachments/" . $_FILES["$_key"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["$_key"]["name"];
        
    } else {
        
        echo $_FILES[$_key]['name'] . ' is invalid';
        
    }

}

 

So $_FILES[$_key]['type'] == "application/pdf" will let pdf files be uploaded, but what is the equivelent for word documents (.doc not .docx)?

 

tried $_FILES[$_key]['type'] == "application/doc" but unfortunately life isnt that simple  :(

 

Thanks

Link to comment
Share on other sites

Your best bet would be to parse the file extension off the file name, and do your logic from that.  :)

 

Thanks for your post nafetski

 

its application/msword though :)

 

are there any benefits of parsing from the filename rather than using the file type?

 

also, how would I go about clipping the extension from the filename as some extensions are 4 characters and some are 3?

Link to comment
Share on other sites

Sure!  Well, there are a few ways that you can get the extension.

 

The way I would probably go about it is using the php explode function, then pulling the last value off the array.

 

Say, explode with using "." as the delimiter...the reason you want to take the last array value is if someone uploads a wonky file like

 

"thisis.mysuperawesome.pdf.but.I.really.wrote.it.in.word.docx"

 

In that case, if you exploded using the "." and took the last value...you would end up with docx :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.