thumbnail creation error while uploading to mysql works
Posted: Sun Feb 25, 2007 12:13 pm
feyd | Please use
************************************************
rest of code:
************************************************
*********************************************************
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!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
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:Code: Select all
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:
************************************************
Code: Select all
<?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!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]