Reply to How to only allow files to be uploaded if they are certain dimensions?

How to only allow files to be uploaded if they are certain dimensions? new!
by George, 15 years, 6 months ago
Hi,
I'm not much of a programmer, my programmer (who I can't get a hold of at the moment) used your script (awesome, by the way!) on one of my sites, and I am trying to modify it so it only allows images to be uploaded if their dimensions are 350x280, I've spent two days trying to make this work and would appreciate any help.

The script I use is below, if anyone can make it so it only allows images to be uploaded if they are 350x280 and displays an error message otherwise I would be SO grateful (and more then willing to PayPal them $10 or so if desired).

if ($_POST['formaction'] == 'Submit') {
  if ($_FILES['image']['name'] <> '') {
    if (($_FILES['image']['type'] == 'image/gif') || ($_FILES['image']['type'] == 'image/jpeg') || ($_FILES['image']['type'] == 'image/pjpeg')) {
      if ($_FILES['image']['error'] > 0) {
        $errormsg = 'Error: '.$_FILES['image']['error'];
      } else {
        $max_preview_image_x = 350;
        $max_thumbnail_image_x = 250;
        $imagepath = '../entry/';
        $tmpUploadPath = './imgtmp/';
        $imagename = $contestid. '-' .date('YmdHis');
        ini_set("max_execution_time",0);
        $handle = new Upload($_FILES['image']);
        if ($handle->uploaded) {
          $handle->Process($tmpUploadPath);
          $info = getimagesize($handle->file_dst_pathname);
          $PreviewImageCurrentPath = $handle->file_dst_pathname;
          if ($info[0] > $max_preview_image_x) {
            $OriginalFile = $PreviewImageCurrentPath;
            $handle->image_resize          = true;
            $handle->image_ratio_y         = true;
            $handle->image_x               = $max_preview_image_x;
            $handle->Process($tmpUploadPath);
            unlink($OriginalFile);
            //echo 'delete file'. $OriginalFile;
            $PreviewImageCurrentPath = $handle->file_dst_pathname;
          }						
          copy( $PreviewImageCurrentPath, $imagepath.'L'.$imagename.'.'.$handle->file_dst_name_ext );						
          // Prepared Preview file
          // Start prepare thumbnail
          $info = getimagesize($handle->file_dst_pathname);
          $ThumbnailCurrentPath = $handle->file_dst_pathname;
          if ($info[0] > $max_thumbnail_image_x) {
            $OriginalFile = $ThumbnailCurrentPath;
            $handle->image_resize          = true;
            $handle->image_ratio_y         = true;
            $handle->image_x               = $max_thumbnail_image_x;
            $handle->Process($tmpUploadPath);
            unlink($OriginalFile);
            //echo 'delete file'. $OriginalFile;
            $ThumbnailCurrentPath = $handle->file_dst_pathname;
          }
          copy( $ThumbnailCurrentPath, $imagepath.'S'.$imagename.'.'.$handle->file_dst_name_ext );						
          unlink($ThumbnailCurrentPath);
          $GeneralImageName = $imagename.'.'.$handle->file_dst_name_ext;
          //echo 'delete file'. $ThumbnailCurrentPath;
          // insert into entry and mark new
          $timestamp = date('Y-m-d H:i:s');
          $query = "INSERT INTO entries (contestid, designerid, entryimage, entryscore, entrytimestamp, entrynew  ) VALUES ('$contestid', '$designerloginid', '$GeneralImageName', 0, '$timestamp', 'T')";
          mysql_query($query, $link);
          mysql_free_result($result);
          $actionmessage = "Entry is submitted.";
        } else {
          $actionmessage = 'File upload failed. Please retry.';
        }
      }
    } else {
      $actionmessage = 'File format is not accepted. Only accept: .gif, .jpg and .jpeg ';
    }				
  } else {
    $actionmessage = 'Please select the file location.';
  }
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important