runnerjp Posted May 9, 2008 Share Posted May 9, 2008 i use this to upload my images and resize them... this is for use as avators but i keep getting this error Warning: imagejpeg() [function.imagejpeg]: Unable to open 'images/thumbs/.jpg' for writing: Permission denied in /home/runningp/public_html/members/uploader.php on line 151 now my image folders are 777 so i have no idea why <?php session_start(); //load the config file include("config.php"); require_once '../config.php'; //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; $user = $logged[username]; $query = "SELECT * FROM members WHERE username='$user' "; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['email']; $puser = $array['username']; $pid = $array['ID']; $pfirst_name = $array['first_name']; $plast_name = $array['last_name']; $pabout_me = $array['about_me']; $pevents = $array['events']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; } } //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$pid.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message //echo "<br>Image Thumb: <a href=\"$path_thumbs/$pid.$file_ext\">$path_thumbs/$pid.$file_ext</a>"; } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$pid.$file_ext"); //echo "<br>Image Big: <a href=\"$path_big/$pid.$file_ext\">$path_big/$pid.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; $query = "INSERT INTO user_images (user_id, ext) VALUES ('$pid', '$file_ext') ON DUPLICATE KEY UPDATE ext = '$file_ext'"; mysql_query($query) or die(mysql_error()); }else{ //if the form hasn't been submitted. //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script>\n\n <br><h3>:: Browse an Image to Upload:</h3>\n <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[php_SELF]\">\n <input type=\"file\" name=\"imgfile\" > <img src='' name='img_vv' width='0'><br>\n Image width will resize to <b>$img_thumb_width</b> with height ratio. <br><input type=\"Submit\" name=\"upForm\" value=\"Upload & Resize\">\n </form> <a href=\"view_gallery.php\">View Images</a>"; } ?> this is the line ImageJpeg ($resized_img,"$path_thumbs/$pid.$file_ext"); also config.php <?php ####################################### //path where to store images $path_thumbs = "images/thumbs"; $path_big = "images/big"; //the new width of the resized image. $img_thumb_width = 200; // in pixcel $extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no) //allowed Extensions $limitedext = array(".gif",".jpg",".png",".jpeg",".bmp"); //check if folders are Writable or not //please CHOMD them 777 if (!is_writeable($path_thumbs)){ die ("Error: The directory <b>($path_thumbs)</b> is NOT writable"); } if (!is_writeable($path_big)){ die ("Error: The directory <b>($path_big)</b> is NOT writable"); } ?> Link to comment https://forums.phpfreaks.com/topic/104885-image-upload/ Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 one problem may be the missing file name in images/thumbs/.jpg: Warning: imagejpeg() [function.imagejpeg]: Unable to open 'images/thumbs/.jpg' for writing: Permission denied in /home/runningp/public_html/members/uploader.php on line 151 Also, you'll probably need to supply the entire path, not just the relative path, e.g., /home/public_html/images/thumbs/somefile.jpg Link to comment https://forums.phpfreaks.com/topic/104885-image-upload/#findComment-536844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.