iamq08 Posted November 26, 2006 Share Posted November 26, 2006 i'm looking to be able to have users upload images on my website, but only images.I poked around a little bit and it seems that imagemagick and/or GD is the way to do this, but i'm not familiar with either, does anyone know:A.)Which method they would recommendB.) Where I can find a solid tutorial or documentation on how to accomplish thisThanks in advance-Iain Link to comment https://forums.phpfreaks.com/topic/28478-uploading-images/ Share on other sites More sharing options...
Philip Posted November 26, 2006 Share Posted November 26, 2006 The following code is from http://www.devpapers.com/article/41 (check there if you want a little more explanation of the coding)Should be exactly what you need :D form.php[code]<form action="upload.php" method="post" ENCTYPE="multipart/form-data">File: <input type="file" name="file" size="30"> <input type="submit" value="Upload!"></form>[/code]upload.php[code] <?php// ==============// Configuration// ==============$uploaddir = "uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!$allowed_ext = "jpg, gif, png, pdf"; // These are the allowed extensions of the files that are uploaded$max_size = "50000"; // 50000 is the same as 50kb$max_height = "100"; // This is in pixels - Leave this field empty if you don't want to upload images$max_width = "100"; // This is in pixels - Leave this field empty if you don't want to upload images// Check Entension$extension = pathinfo($_FILES['file']['name']);$extension = $extension[extension];$allowed_paths = explode(", ", $allowed_ext);for($i = 0; $i < count($allowed_paths); $i++) { if ($allowed_paths[$i] == "$extension") { $ok = "1"; }}// Check File Sizeif ($ok == "1") {if($_FILES['file']['size'] > $max_size){print "File size is too big!";exit;}// Check Height & Widthif ($max_width && $max_height) {list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);if($width > $max_width || $height > $max_height){print "File height and/or width are too big!";exit;}}// The Upload Partif(is_uploaded_file($_FILES['file']['tmp_name'])){move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);}print "Your file has been uploaded successfully! Yay!";} else {print "Incorrect file extension!";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28478-uploading-images/#findComment-130313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.