Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Find where an error occurs.</p> <pre><code>&lt;?php $msg = ''; $upload_key = 'uploaded_file'; if (isset($_FILES[$upload_key])) { try { $error = $_FILES[$upload_key]['error']; switch ($error) { case UPLOAD_ERR_INI_SIZE: throw new Exception('Exceeded upload_max_filesize'); case UPLOAD_ERR_FORM_SIZE: throw new Exception('Exceeded MAX_FILE_SIZE'); case UPLOAD_ERR_PARTIAL: throw new Exception('Incomplete file uploaded'); case UPLOAD_ERR_NO_FILE: throw new Exception('No file uploaded'); case UPLOAD_ERR_NO_TMP_DIR: throw new Exception('No tmp directory'); case UPLOAD_ERR_CANT_WRITE: throw new Exception('Can\'t write data'); case UPLOAD_ERR_EXTENSION: throw new Exception('Extension error'); } $finfo = new finfo(FILEINFO_MIME); $name = $_FILES[$upload_key]['name']; $tmp_name = $_FILES[$upload_key]['tmp_name']; $size = $_FILES[$upload_key]['size']; if ($size &gt; 350000) throw new Exception('Exceeded 350KB limit'); if (!is_uploaded_file($tmp_name)) throw new Exception('Not an uploaded file'); $type = $finfo-&gt;file($tmp_name); if ($type === false) throw new Exception('Failed to get MimeType'); if ($type !== 'image/jpeg; charset=binary') throw new Exception('Only JPEG files available'); $new_name = dirname(__FILE__).'/upload/'.$name; if (is_file($new_name)) throw new Exception("The file {$new_name} already exists"); if (!move_uploaded_file($tmp_name,$new_name)) throw new Exception('Failed to move uploaded file'); $msg = "File successfully uploaded as {$new_name}"; } catch (Exception $e) { $msg = 'Error: '.$e-&gt;getMessage(); } } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Uploader&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form enctype="multipart/form-data" action="&lt;?php echo $_SERVER['SCRIPT_NAME']; ?&gt;" method="post"&gt; &lt;div&gt;&lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000" /&gt;&lt;/div&gt; &lt;div&gt;Choose a file to upload: &lt;input name="uploaded_file" type="file" /&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="submit" value="Upload" /&gt;&lt;/div&gt; &lt;/form&gt; &lt;p&gt; &lt;?php echo $msg.PHP_EOL; ?&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload