pelko Posted January 10, 2010 Share Posted January 10, 2010 Hi! Can someone add a function that is checking if picture witdh is bigger then 800px whwn uploading, then echo "image oversized" to the code below? <?php ###/ VARIABLES - CHANGE ACCORDINGLY define("VAR_BASE_DIRECTORY","/home/web30217/domains/mysite.com/public_html/"); define("VAR_UPLOAD_FOLDER","upload/"); define("VAR_UPLOAD_DIRECTORY",VAR_BASE_DIRECTORY.VAR_UPLOAD_FOLDER); define("VAR_UPLOAD_FIELDS",1); define("VAR_FILENAME_KEEP",0); ##/ Function that displays forms and is called by default function defaultForm() { echo "<form method=\"post\" enctype=\"multipart/form-data\">\n"; for($i=0; $i < VAR_UPLOAD_FIELDS; $i++) { echo "<input name=\"file[]\" type=\"file\" id=\"file[]\" /><br />\n"; echo "<div style=\"height:2px\"></div>"; } echo "<div style=\"height:1px\"></div>"; echo "<br /><input name=\"Submit\" type=\"image\" src=\"/images/upload.jpg\" value=\"Ladda upp\">\n"; echo "<input name=\"filter\" type=\"hidden\" value=\"processForm\">\n"; echo "</form>\n"; return; } #/ End of defaultForm ##/ Function that displays forms and is called by default function processForm() { for($i=0; $i < VAR_UPLOAD_FIELDS; $i++) { echo ""; if(!empty($_FILES[file][size][$i])) { if(VAR_FILENAME_KEEP==1) { ##/ File maintaining upload name $fileName = $_FILES[file][name][$i]; } else { ##/ Filename randomized $fileName = rand(10000,400000).rand(1,10).'.' . substr($_FILES[file][name][$i], -3); } ##/ Creating reference address $newLocation = VAR_UPLOAD_DIRECTORY.$fileName; if(!copy($_FILES[file][tmp_name][$i],$newLocation)) { echo "<b>Failed - ".$_FILES[file][name][$i]." would not copy to ".$newLocation."</b> (Check your upload directory and permissions)"; } else { ###/ SUCCESS /### #/ Stripping of VAR_BASE_DIRECTORY for better viewing and linking $urlShow = str_replace(VAR_BASE_DIRECTORY,'',$newLocation); echo "[img]http://mysite.com/$urlShow[/img]"; } } else { echo ""; } echo "<br />"; } return; } #/ End of processForm ##/ This object handles which function the application should call switch($_POST[filter]) { case "processForm": processForm(); break; default: defaultForm(); break; } #/ End of Handling ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted January 10, 2010 Share Posted January 10, 2010 imagesx Will give you the width of an image. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted January 10, 2010 Share Posted January 10, 2010 if(imagesx($file) > 800) { // Bigger than 800 code here }else{ // Below or equal to 800 here } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.