note 107295 added to features.file-upload.errors

From: Date: Sat, 28 Jan 2012 06:09:49 +0000
Subject: note 107295 added to features.file-upload.errors
Groups: php.notes 
Request: Send a blank email to php-notes+get-185774@lists.php.net to get a copy of this message
<?php /* If you ever try to upload an empty file using fread(), php may show a nasty warning (according to your "error_reporting") about "Length parameter must be greater than 0" especially if you are parsing this as xml. So in order to handle this error from here you may do the next: */ $file = $_FILES['file']; $error_text = true; // Show text or number define("UPLOAD_ERR_EMPTY",5); if($file['size'] == 0){ $file['error'] = 5; } $upload_errors = array( UPLOAD_ERR_OK => "No errors.", UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.", UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.", UPLOAD_ERR_PARTIAL => "Partial upload.", UPLOAD_ERR_NO_FILE => "No file.", UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.", UPLOAD_ERR_CANT_WRITE => "Can't write to disk.", UPLOAD_ERR_EXTENSION => "File upload stopped by extension.", UPLOAD_ERR_EMPTY => "File is empty." // add this to avoid an offset ); // error: report what PHP says went wrong $err = ($error_text) ? $upload_errors[$file['error']] : $file['error'] ; header("Content-Type: text/xml"); echo '<errors> <error>'. $err .' </error> </errors> '; // Add your code to prevent fread() to run, either from here or with a previous "if" ?> ---- Server IP: 69.147.83.197 Probable Submitter: 190.51.177.110 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.errors.php Edit -- https://master.php.net/note/edit/107295 Del: integrated -- https://master.php.net/note/delete/107295/integrated Del: useless -- https://master.php.net/note/delete/107295/useless Del: bad code -- https://master.php.net/note/delete/107295/bad+code Del: spam -- https://master.php.net/note/delete/107295/spam Del: non-english -- https://master.php.net/note/delete/107295/non-english Del: in docs -- https://master.php.net/note/delete/107295/in+docs Del: other reasons-- https://master.php.net/note/delete/107295 Reject -- https://master.php.net/note/reject/107295 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185774) next »