Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this code with a bit more error checking, a few corrections and some general improvements. Everything commented, if you don't understand anything just ask:</p> <pre><code>// Try not to over-use parenthesis, it makes code less readable. You only need them to group conditions. if (isset($_POST["MM_insert"]) &amp;&amp; $_POST["MM_insert"] == "form1") { // Pass through basename() for sanitization $pubID = basename($_POST['pubID']); $size = 260; // the thumbnail height $filedir = '../images/gallery/'.$pubID.'/'; // the directory for the original image $thumbdir = '../images/gallery/'.$pubID.'/thumb/'; // the directory for the thumbnail image $maxfile = '2000000'; // PHP understands proper octal representations - no need to turn it into a string $mode = 0777; if (isset($_FILES['Gallimage']['name'])) { // Get upload info and create full paths $userfile_name = $_FILES['Gallimage']['name']; $userfile_tmp = $_FILES['Gallimage']['tmp_name']; $userfile_size = $_FILES['Gallimage']['size']; $userfile_type = $_FILES['Gallimage']['type']; $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$userfile_name; // Create directories if they don't exist - this is the crux of your problem if (!is_dir($filedir)) { mkdir($filedir, $mode, TRUE) or die('Unable to create storage directory'); } if (!is_dir($thumbdir)) { mkdir($thumbdir, $mode, TRUE)) or die('Unable to create thumb directory'); } // Move it to the correct location and set permissions move_uploaded_file($userfile_tmp, $prod_img) or die('Unable to move file to main storage directory'); chmod($prod_img, $mode) or die('Unable to set permissions of file'); // Get info about the image $sizes = getimagesize($prod_img); $aspect_ratio = $sizes[1] / $sizes[0]; if ($sizes[1] &lt;= $size) { $new_width = $sizes[0]; $new_height = $sizes[1]; } else { $new_height = $size; $new_width = abs($new_height / $aspect_ratio); } // Create image resources $destimg = imagecreatetruecolor($new_width, $new_height) or die('Problem in creating image'); $srcimg = imagecreatefromjpeg($prod_img) or die('Problem in opening source Image'); // Manipulate the image if (function_exists('imagecopyresampled')) { imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg)) or die('Problem in resizing'); } else { imagecopyresized($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg)) or die('Problem in resizing'); } // Save the thumbnail and destroy the resources imagejpeg($destimg, $prod_img_thumb, 90) or die('Problem in saving'); imagedestroy($destimg); } // More code here? If not, merge all of this into a single if block } </code></pre>
    singulars
    1. This table or related slice is empty.
    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