Hello all! Could someone please, help me to insert an error into this code, so that if someone uploads an image that is bigger than 300x220 pixels it throws an error saying "The image you're trying to upload is too big. The allowed size is 300x220 pixels." Here's the code: //check if file type is valid. if( move_uploaded_file($_FILES['tf']['tmp_name'],$folder . $fname) ) { if(move_uploaded_file($_FILES['ts']['tmp_name'],$folder2 . $fname2)) { //if file is able to be uploaded upload it to the correct folder echo "Thank you for uploading your theme! You can now <a href='http://themes.rock-kitty.net/upload.php'>upload another theme</a> or return to the <a href='http://themes.rock-kitty.net'>homepage</a>"; //send an email also $this->Email($name,$fname); } else { echo "Error uploading image."; } } else { echo "Error uploading zip/rar file"; } } else { //throw SQL problem telling there was a problem inputting data into database. echo "There was an error when trying to insert data into the database. Please contact the administrator."; } } else { echo "This file type is not allowed."; } } else { echo "There was a field left empty, please, go <a href='javascript:history.go(-1)'>back</a> and check all fields."; } } } function valid_file_type($file) { $file_types = array("zip","rar"); $file = explode(".",$file); $f = $file[count($file)-1]; if( in_array($f,$file_types) ) { return true;//return true if file type isn't .zip or .rar } return false;//return false if file type isn't .zip or .rar } PHP: Thanks!
//check if file type is valid. if( move_uploaded_file($_FILES['tf']['tmp_name'],$folder . $fname) ) { if(move_uploaded_file($_FILES['ts']['tmp_name'],$folder2 . $fname2)) { list($width, $height, $type, $attr) = getimagesize($folder2 . $fname2); if($width < 300 && $height<220){ //if file is able to be uploaded upload it to the correct folder echo "Thank you for uploading your theme! You can now <a href='http://themes.rock-kitty.net/upload.php'>upload another theme</a> or return to the <a href='http://themes.rock-kitty.net'>homepage</a>"; //send an email also $this->Email($name,$fname); }else{ echo "The image you're trying to upload is too big. The allowed size is 300x220 pixels."; } } else { echo "Error uploading image."; } } else { echo "Error uploading zip/rar file"; } } else { //throw SQL problem telling there was a problem inputting data into database. echo "There was an error when trying to insert data into the database. Please contact the administrator."; } } else { echo "This file type is not allowed."; } PHP:
Are the uploaded files actually compressed files (zip, rar)? Because you'd have to uncompress them first before checking the image size. The ZIPs won't be much of a problem, but the RARs might be, because you need the RAR Library to be installed on your server. (shell access might be sufficient as well) And which version of PHP are you using? Also, make sure to convert the file extension to lower case when comparing to the allowed ones. Because some users might have an unexpected case and this would cause the script to reject valid files. $f = strtolower($file[count($file)-1]); PHP:
//check if file type is valid. list($width, $height, $type, $attr) = getimagesize($_FILES['tf']['tmp_name']); if($width < 300 && $height<220){ if( move_uploaded_file($_FILES['tf']['tmp_name'],$folder . $fname) ) { if(move_uploaded_file($_FILES['ts']['tmp_name'],$folder2 . $fname2)) { //if file is able to be uploaded upload it to the correct folder echo "Thank you for uploading your theme! You can now <a href='http://themes.rock-kitty.net/upload.php'>upload another theme</a> or return to the <a href='http://themes.rock-kitty.net'>homepage</a>"; //send an email also $this->Email($name,$fname); } else { echo "Error uploading image."; } } else { echo "Error uploading zip/rar file"; } } else { //throw SQL problem telling there was a problem inputting data into database. echo "There was an error when trying to insert data into the database. Please contact the administrator."; } } else { echo "This file type is not allowed."; } else{ echo "The image you're trying to upload is too big. The allowed size is 300x220 pixels."; } PHP:
It gives me an error: Parse error: syntax error, unexpected T_ELSE in /home/***/public_html/***/***/***.php on line 134 Line 134 is this: else{
I tried, but it gave me: Parse error: syntax error, unexpected $end in /home/***/public_html/***/***/***.php on line 241
Lol, it'd be a little easier if we could see the rest of your code because there are a lot of "else"s which we don't know about. Anyway, give this a try. I don't see any apparent reasons why this wouldn't work. //check if file type is valid. list($width, $height) = @getimagesize($_FILES['ts']['tmp_name']); if ($width < 300 && $height < 220) { if (@move_uploaded_file($_FILES['tf']['tmp_name'], $folder . $fname) ) { if (@move_uploaded_file($_FILES['ts']['tmp_name'], $folder2 . $fname2)) { //if file is able to be uploaded upload it to the correct folder echo "Thank you for uploading your theme! You can now <a href='http://themes.rock-kitty.net/upload.php'>upload another theme</a> or return to the <a href='http://themes.rock-kitty.net'>homepage</a>"; //send an email also $this->Email($name,$fname); } else { echo "Error uploading image."; } } else { echo "Error uploading zip/rar file"; } } else { echo "The image you're trying to upload is too big. The allowed size is 300x220 pixels."; } } else { //throw SQL problem telling there was a problem inputting data into database. echo "There was an error when trying to insert data into the database. Please contact the administrator."; } } else { echo "This file type is not allowed."; } PHP: The last error you got means that there's a curly bracket missing. So if you get the same error again, perhaps you can spot it without having to post your full code.
Sorry for the late reply, I've been very busy and didn't have to work on this issue. The code works, but it still uploads the theme even though it gives an error that the image size is too big. EDIT: Nico fixed it for me, thanks!