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 Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/ Share on other sites More sharing options...
thebadbad Posted June 14, 2009 Share Posted June 14, 2009 ~^[\da-z-]+\.zip$~iD Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/#findComment-855826 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 } ?> Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/#findComment-855857 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 Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/#findComment-857386 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. Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/#findComment-857394 Share on other sites More sharing options...
ballouta Posted June 16, 2009 Author Share Posted June 16, 2009 yes you are right thanks alot Link to comment https://forums.phpfreaks.com/topic/162174-solved-check-extension/#findComment-857397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.