Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to use the PHP function <code>getimagesize();</code></p> <p>The getimagesize() function does not require the GD library.</p> <p>Try this:</p> <pre><code>&lt;?php // Set maximum width and height in pixels $maxwidth = 4000; $maxheight = 4000; $allowedExts = array("png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) &amp;&amp; ($_FILES["file"]["size"] &lt; 20000) &amp;&amp; in_array($extension, $allowedExts)) { // List the width, height, image type, img attributes of the uploaded file into the specified variables list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize($_FILES["file"]["tmp_name"]); // If the image is too wide, or if the image is too tall, don't upload and tell the user. if($imgwidth &lt; $maxwidth || $imgheight &lt; $maxheight){ if ($_FILES["file"]["error"] &gt; 0) { echo "Error: " . $_FILES["file"]["error"] . "&lt;br&gt;"; } else { echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;"; echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; $path = "/path/to/file"; move_uploaded_file($_FILES["file"]["tmp_name"], $path."/".$_SESSION['Username'].".png"); } }else{ echo "File width or height is too large."; } } else { echo "Invalid file"; } ?&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.
    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