FRSH Posted July 30, 2011 Share Posted July 30, 2011 I'm trying to upload only zip files to the upload directory. Here is the code for verify_upload.php <?php //does pluginfile exist? //if (isset($_POST['pluginfile'])) { // Set all the vadiables $name = $_FILES["file"] ["name"]; $type = $_FILES["file"] ["type"]; $size = $_FILES["file"] ["size"]; $tmp_name = $_FILES["file"] ["tmp_name"]; $error = $_FILES["file"] ["error"]; echo $type; //is the filetype rar/zip? if($type == "application/x-zip-compressed" || "application/zip") { //does the filename already exist? if (file_exists("/upload/".$name)) { //how do I add a _1 to the filename if it already exists? $message ="filename already exists"; }//filename $destination_path = "/upload/"; $target_path = $destination_path . basename($name); if(@move_uploaded_file($tmp_name, $target_path)) { //Upload successful! $message = "file uploaded successfuly!"; } }//if the filetype is not valid else { $message = "only zip and rar filetypes are allowed"; } //}//pluginfile exists //else { //$message .="No file was detected"; //} if(!empty($message)) { echo $message; } ?> Here is the code for the form: <html> <head></head> <body> <form enctype="multipart/form-data" action="verify_upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="file" id="file" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/ Share on other sites More sharing options...
FRSH Posted July 30, 2011 Author Share Posted July 30, 2011 10 views and no reply? am I missing something obvious? Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/#findComment-1249275 Share on other sites More sharing options...
skwap Posted July 30, 2011 Share Posted July 30, 2011 try below code <?php if($_SERVER['REQUEST_METHOD']=='POST') { // Set all the vadiables $name = $_FILES["file"] ["name"]; $type = $_FILES["file"] ["type"]; $size = $_FILES["file"] ["size"]; $tmp_name = $_FILES["file"] ["tmp_name"]; $error = $_FILES["file"] ["error"]; //is the filetype rar/zip? if($type == "application/x-zip-compressed" && "application/zip") { //does the filename already exist? if (file_exists("/upload/".$name)) { //how do I add a _1 to the filename if it already exists? $message ="filename already exists"; }//filename $destination_path = "/upload/"; $target_path = $destination_path . basename($name); if(@move_uploaded_file($tmp_name, $target_path)) { //Upload successful! $message = "file uploaded successfuly!"; } }//if the filetype is not valid else { $message = "only zip and rar filetypes are allowed"; } //}//pluginfile exists //else { //$message .="No file was detected"; //} if(!empty($message)) { echo $message; } } ?> Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/#findComment-1249283 Share on other sites More sharing options...
FRSH Posted July 30, 2011 Author Share Posted July 30, 2011 It does not work for some reason. The two codes that I have tried have both returned a blank page. Its really annoying, can somebody help!? Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/#findComment-1249413 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 check this link. http://www.phpfreaks.com/forums/index.php?board=1.0 Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/#findComment-1249419 Share on other sites More sharing options...
Ninjakreborn Posted July 30, 2011 Share Posted July 30, 2011 viop03 - Your link didn't work. OP - http://designshack.co.uk/articles/php-articles/smart-file-type-detection-using-php/ Link to comment https://forums.phpfreaks.com/topic/243243-quick-file-upload-help-please/#findComment-1249462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.