I don’t know if either option is simipler. Certainly it’s not possible to limit the dimensions of the image before upload, but you can reject it once the file has been uploaded which is an utter pain if you’re on a slow connection uploading a large file.
I was depending on Wordpress to handle post formatting of images and files via their attachment mechanism. Currently there is no option to resize images apon upload, but it does generate three “sizes” – thumbnail, medium and original. To force the original to be a specific size requires additional code. I don’t know if I’ll get around to in the near future as I’m considering creating a new upload files widget.
Hi,
I just posted a small explanation for outputting thumbs or medium sized images in templates.
check: this thread
I was able to limit the accepted dimensions (height x width) for images uploaded by editing the upload-inline.php file but I can’t figure out how to display the image size error correctly instead I’m using die to exit the script. I would like for the upload file form to be reset like it does when there’s an image size error. any suggestions? this is what I added to the script:
if(isset($_POST['tdomf_upload_inline_submit_'.$form_id])) { //see if submit button is pressed.
//check if they decided to upload a pic:
if($_FILES["uploadfile".$form_id."_".$i]['size'] > 1) {$max_height = 800;
$max_width = 600;$info = getimagesize($_FILES["uploadfile".$form_id."_".$i]['tmp_name']);
//check the extension.
$array = explode(“.”, $_FILES["uploadfile".$form_id."_".$i]['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !=”jpg”) && ($ext !=”jpeg”) && ($ext !=”png”))
die(“Error: file extension un-recognized.
Be sure your image follows the correct extension (.JPG or .PNG)”);//CHECK TYPE: (what the browser sent)
if(($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/jpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] !=
“image/pjpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.”);
}//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize()
//-In case it was a FAKE!
if(($info['mime'] != “image/jpeg”) && ($info['mime'] != “image/pjpeg”) &&
($info['mime'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.”);
}//check file size (length & width)
if(($info[0] != $max_width) || ($info[1] !=$max_height)) {
die(“Error: Image size error (” . $info[0] .
“ x ” . $info[1] . “). Must not exceed “. $max_width .
” x “. $max_height .”.”);
}
}
}
I’ve already solved my problem but this is how the code looks on upload-inline.php
Before code:
// Move the uploaded file to the temp storage path
//
for($i = 0; $i < $options['max']; $i++) {
$upload_temp_file_name = $_FILES["uploadfile".$form_id."_".$i]['tmp_name'];
$upload_file_name = $_FILES["uploadfile".$form_id."_".$i]['name'];
$upload_error = $_FILES["uploadfile".$form_id."_".$i]['error'];
$upload_size = $_FILES["uploadfile".$form_id."_".$i]['size'];
$upload_type = $_FILES["uploadfile".$form_id."_".$i]['type'];
Added code:
if(isset($_POST['tdomf_upload_inline_submit_'.$form_id])) { //see if submit button is pressed.
//check if they decided to upload a pic:
if($_FILES["uploadfile".$form_id."_".$i]['size'] > 1) {$max_height = 800;
$max_width = 600;$info = getimagesize($_FILES["uploadfile".$form_id."_".$i]['tmp_name']);
//check the extension.
$array = explode(“.”, $_FILES["uploadfile".$form_id."_".$i]['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !=”jpg”) && ($ext !=”jpeg”) && ($ext !=”png”))
die(“Error: file extension un-recognized.
Be sure your image follows the correct extension (.JPG or .PNG)Click here to try again“);//CHECK TYPE: (what the browser sent)
if(($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/jpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] !=
“image/pjpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.Click here to try again“);
}//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize()
//-In case it was a FAKE!
if(($info['mime'] != “image/jpeg”) && ($info['mime'] != “image/pjpeg”) &&
($info['mime'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.Click here to try again“);
}//check file size (length & width)
if(($info[0] != $max_width) || ($info[1] !=$max_height)) {
die(“Error: (” . $info[0] .
“ x ” . $info[1] . “) is not the correct size. Only “. $max_width .
” x “. $max_height .” images allowed.Click here to try again“);
}
}
}
After code:
if(is_uploaded_file($upload_temp_file_name)) {
// double check file extension
Mark Cunningham
Guest
December 2nd, 2008 at 11:27 am
Do you mean, how to limit the dimensions of the image uploaded or modify it after uploading?
Permalink | Quote