Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Response Script for question: http://answers.yahoo.com/question/?qid=20110628154908AABkmr6
- */
- $siteLive = false; // Determines which messages to display.
- if($siteLive){
- // Upload Errors ** NOTE ** There is no error number 5. It was an old error, removed.
- $uploadErrors = array(
- 1 => 'The Selected File, exceeds the maximum file size allowed. Please alter the file, or select an alternate.',
- 2 => 'The Selected File, exceeds the maximum file size allowed. Please alter the file, or select an alternate.',
- 3 => 'Your upload connection was dis-connected. Please try again.',
- 4 => 'Please Select A File To Upload.',
- 6 => 'Internal Server Error. Please try again later. If the problem persists, please inform the site administrator.', // Internal Operations Error
- 7 => 'Internal Server Error. Please try again. If the problem persists, please inform the site administrator.', // Internal Server Error
- 8 => 'Internal Server Error. Please try again. If the problem persists, please inform the site administrator.' // PHP Extension Library stopped the upload.
- );
- }else{
- // Upload Errors ** NOTE ** There is no error number 5. It was an old error, removed.
- $uploadErrors = array(
- 1 => 'The uploaded file exceeds the Server\'s Maximum Allowable File Size', // Both the server and form have max file size limitations
- 2 => 'The uploaded file exceeds the Form\'s Maximum Allowable File Size.',
- 3 => 'The uploaded file was only partially uploaded, then interrupted or the connection was dropped.',
- 4 => 'No file was uploaded.', // No file was selected for upload.
- 6 => 'Missing a temporary folder. The server requires a temporary folder for file uploads.', // Internal Operations Error
- 7 => 'Failed to write file to disk.', // Internal Server Error
- 8 => 'A PHP extension stopped the file upload.' // PHP Extension Library stopped the upload.
- );
- }
- if($_SERVER['REQUEST_METHOD'] === "POST"){
- $_fup = $_FILES['uploaded'];
- if($_fup['error'] === UPLOAD_ERR_OK){
- $upDir = "uploads";
- if(!is_dir($upDir)){
- mkdir($upDir, 0777, true);
- }
- $target_path = $upDir . DIRECTORY_SEPARATOR . basename($_fup['name']);
- if(move_uploaded_file($_fup['tmp_name'], $target_path)) {
- echo "The file " . basename($_fup['name']) . " has been uploaded";
- } else{
- echo "There was an error uploading the file, please try again!";
- }
- }else{
- echo $uploadErrors[$_fup['error']] . '<br >';
- }
- }
- ?>
- <form id="form1" name="form1" enctype="multipart/form-data" action="" method="POST">
- Please choose a file:
- <input type="hidden" name="MAX_FILE_SIZE" value="200000" />
- <input name="uploaded" type="file" />
- <input type="submit" value="Upload" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement