vikela Posted March 10, 2009 Share Posted March 10, 2009 i am new to php and i have this cool code to upload files which is giving me nothing can anyone help?its not loading any files and i have created a folder called images but when i look in it there is nothing <?php //Make all definitions define('UP_DIR', 'C:\localhost\test\\'); define('MAX_FILE_SIZE', 10240000); define('IMAGE', 'pics\\'); define('VIDEO', 'vids\\'); define('APP', 'other\\'); //Initialise flags $sizeOK = false; $typeOK = false; $success = false; $video = false; $image = false; $app = false; //Create an array of permitted MIME types $allowed = array( 'application/msword', 'application/pdf', 'text/plain', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/rtf', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'video/avi', 'application/x-zip-compressed', 'audio/mpeg', 'text/xml', 'image/bmp'); if(array_key_exists('upload', $_POST)) { //Replace any spaces in the original name for underscores $file = str_replace(' ', '_', $_FILES['file']['name']); //convert the max size to kb $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; //Check the file type is permitted foreach($allowed as $type) { if($type == $_FILES['file']['type']) { $typeOK = True; //Check to see which folder to place them in if(substr($type, 12) == 'msword' || substr($type, 12) == 'pdf' || substr($type, 5) == 'plain' || substr($type, 5) == 'rtf' || substr($type, 5) == 'xml') { $app = True; } elseif(substr($type, 6) == 'gif' || substr($type, 6) == 'jpeg' || substr($type, 6) == 'png' || substr($type, 6) == 'pjpeg' || substr($type, 6) == 'bmp') { $image = True; } elseif(substr($type, 12) == 'vnd.openxmlformats-officedocument.wordprocessingml.document' || substr($type, 12) == 'x-zip-compressed') { $app = True; //Office 2007 } elseif(substr($type, 5) == 'avi') { $video = True; } break; } } //check it isn't too big if($_FILES['file']['size'] > 0 && $_FILES['file']['size'] <= MAX_FILE_SIZE) { $sizeOK = True; } if($sizeOK && $typeOK) { //Lets see what the error level is switch($_FILES['file']['error']) { case 0: //Move file to folder and rename it if($app) { $success = move_uploaded_file($_FILES['file']['tmp_name'], UP_DIR.APP.$file); } elseif($image) { $success = move_uploaded_file($_FILES['file']['tmp_name'], UP_DIR.IMAGE.$file); } elseif($video) { $success = move_uploaded_file($_FILES['file']['tmp_name'], UP_DIR.VIDEO.$file); } //Make sure it was moved with no problems if($success) { $result = "$file uploaded successfully"; } else { $result = "Error uploading $file. Please try again."; } break; case 2: //we ignore error 1 because it is php.ini //File was too big! $result = "$file was too big to be uploaded. Please try a smaller file"; break; case 4: //No file selected $result = "No file was selected, please go back and try again"; break; default: $result = "System error uploading $file. Please contact a staff member to resolve this issue."; } } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: .doc, .txt, .pdf, .jpg, .jpeg, .gof, .rtf, .png"; } } //If the form has been submitted, display the result if(isset($result)) { echo("<p><b>$result</b></p>"); } ?> <form action="" method="post" enctype="multipart/form-data" name="uploadFiles" id="uploadFiles"> <label for="file"> Upload File: </label> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="file" name="file" id="file" /> <input type="submit" name="upload" value="upload" /> </form> Link to comment https://forums.phpfreaks.com/topic/148739-file-uploading-not-loading/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.