weeping Posted February 25, 2007 Share Posted February 25, 2007 hello, i first tried to upload images to mysql and in the same time to generate thumbnails in the same mysql query - which didnt worked so i want now to submit/upload an image to mysql and in the same time to generate its thumbnail inside a directory on the server BUT i have this problem that the image i 'browse' for need to be in the same directory with my .php scripts... i will post the code and the error i get : the function used for creating thumbnails: function createthumb($name,$filename,$new_w,$new_h){ $system=explode('.',$name); if (preg_match('/jpg|jpeg/',$system[1])){ $src_img=imagecreatefromjpeg($name); } if (preg_match('/png/',$system[1])){ $src_img=imagecreatefrompng($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } ************************************************ rest of code: ************************************************ <?php include 'init.php'; if(!isset($_POST['upload'])) { include 'addform.php'; exit; } else { function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $file_name = stripslashes($_FILES['image']['name']); $extension = getExtension($file_name); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $ext_error = 'Unknown extension!'; include 'add.php'; exit; } define ("MAX_SIZE","5000"); $sizekb=filesize($_FILES['image']['tmp_name']); if ($sizekb > MAX_SIZE*5000) { $size_error = 'You have exceeded the size limit!'; include 'add.php'; exit; } // $file_name = $_FILES['image']['name']; $temp_name = $_FILES['image']['tmp_name']; $file_size = $_FILES['image']['size']; $file_type = $_FILES['image']['type']; $var = fopen($temp_name, 'r'); $content = fread($var, filesize($temp_name)); $content = addslashes($content); fclose($var); if(!get_magic_quotes_gpc()) { $file_name = addslashes($file_name); } $user = 'test2'; $path="thumbs\\$user"; mkdir($path,0777,TRUE); include 'fct.php'; $filename = "$path\\thumb_$file_name"; createthumb($file_name,$filename,120,150); $query = "INSERT INTO upload (name, size, type, picture) ". "VALUES ('$file_name', '$file_size', '$file_type', '$content')"; mysql_query($query) or die ('Could not insert into dB!'); $ok = 'Thumbnail created Successfully!'; $path_to_images = "thumbs/$user/"; $default_img = ""; include 'addform.php'; exit; } ?> ********************************************************* The errors: ********************************************************* Warning: imagecreatefromjpeg(gkoufay04.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in E:\www\fct.php on line 6 Warning: imagesx(): supplied argument is not a valid Image resource in E:\www\fct.php on line 12 Warning: imagesy(): supplied argument is not a valid Image resource in E:\www\fct.php on line 13 Warning: Division by zero in E:\www\fct.php on line 26 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in E:\www\fct.php on line 29 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in E:\www\fct.php on line 30 Warning: imagejpeg(): supplied argument is not a valid Image resource in E:\www\fct.php on line 36 Warning: imagedestroy(): supplied argument is not a valid Image resource in E:\www\fct.php on line 39 Warning: imagedestroy(): supplied argument is not a valid Image resource in E:\www\fct.php on line 40 ********************************************* as i said i get these errors when trying to submit a image which is not in the same directory with my .php files. the image gets writen to blob field inside sql but the thumbnail doesnt generate (it generates when source image is toghether with php files...) HELP PLEASE !!! 10x! Link to comment https://forums.phpfreaks.com/topic/40059-upload-images-and-generate-thumbnails-in-the-same-query/ Share on other sites More sharing options...
itsmeArry Posted February 27, 2007 Share Posted February 27, 2007 instead of using $file_name = stripslashes($_FILES['image']['name']); try this $file_name = $_FILES['image']['tmp_name']; Link to comment https://forums.phpfreaks.com/topic/40059-upload-images-and-generate-thumbnails-in-the-same-query/#findComment-195232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.