amavadia Posted March 9, 2010 Share Posted March 9, 2010 Does anyone know of any functions which allow you to upload multiple files to a webserver and saves them there as a ZIP archive automatically? Thanks Quote Link to comment Share on other sites More sharing options...
The Eagle Posted March 9, 2010 Share Posted March 9, 2010 Or have multiple files on your computer, put them into a ZIP archive and upload the ZIP to your webserver? Works the same way, just in my opinion, easier. Is that want you want to accomplish? Quote Link to comment Share on other sites More sharing options...
amavadia Posted March 9, 2010 Author Share Posted March 9, 2010 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. Quote Link to comment Share on other sites More sharing options...
amavadia Posted March 9, 2010 Author Share Posted March 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Your best bet would be to parse the file extension off the file name, and do your logic from that. Quote Link to comment Share on other sites More sharing options...
amavadia Posted March 9, 2010 Author Share Posted March 9, 2010 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? Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.