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.

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

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?

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.