ballouta Posted June 14, 2009 Share Posted June 14, 2009 Kindly I need a reg that validates an uploaded file, it should always be .zip (the name may contain numbers/letters/and dashes only) Many thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 14, 2009 Share Posted June 14, 2009 ~^[\da-z-]+\.zip$~iD Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 14, 2009 Share Posted June 14, 2009 And you should also check if the file really is a ZIP, and not just a spoofed file with the zip extension. Code: <?php //$filedata is the data of the uploaded file $start = substr($filedata, 0, 4); if ($start == "PK\003\004") { //data is ZIP file including packed files } elseif ($start == "PK\005\006") { //data is an empty ZIP file } else { //spoofed data, not a ZIP file } ?> Quote Link to comment Share on other sites More sharing options...
ballouta Posted June 16, 2009 Author Share Posted June 16, 2009 Thanks for this important validation BUT the reg is not accepting a file name with space or letters or dashes, kindly may you edit it, wish i know who to do it many thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 16, 2009 Share Posted June 16, 2009 Here you go: ~^[\da-z -]+\.zip$~iD I just added a space inside the character class. And remember that whitespace not is allowed in an URL, so it would be a good idea to strip or convert any spaces when you save the file. Quote Link to comment Share on other sites More sharing options...
ballouta Posted June 16, 2009 Author Share Posted June 16, 2009 yes you are right thanks alot 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.