Jump to content

gd script showing error


vinpkl

Recommended Posts

hi all

 

i m using the following gd script

http://www.anyexample.com/programming/php/php_multiple_photo_thumbnail_generator.xml

 

<?php 
// Don't forget to change next two variables
// Or create web-server writable directory aeupload in 
// the directory with this php file
$upload_dir = "e:/www/htdocs/upload"; 
// Directory for file storing                          
// filesystem path
$web_upload_dir = "/www/htdocs/upload"; 
//chmod('/test_images/', 0777); 
// Directory for file storing                              
// web-server dir 
/* upload_dir is filesystem path, something like    
/var/www/htdocs/files/upload or c:/www/files/upload     
web upload dir, is the webserver path of the same    
directory. If your upload-directory accessible under     
www.your-domain.com/files/upload/, then     web_upload_dir is /files/upload */
// testing upload dir 

// * * * * * // INSERT SOURCE CODE OF thumbnail_calcsize() AND thumbnail_generator() HERE // * * * * *
function thumbnail_calcsize($w, $h, $square)
{    
$k = $square / max($w, $h);    
return array($w*$k, $h*$k);
}   



function thumbnail_generator($srcfile, &$params){   
// getting source image size    
@list($w, $h) = getimagesize($srcfile);    
if ($w == false)        
return false;    
// checking params array     
if (!(is_array($params)&&is_array($params[0])))        
return false;    
$src = ImageCreateFromJpeg($srcfile);    
list($s1_w, $s1_h) = thumbnail_calcsize($w, $h, $params[0]['size']);    
// Create first thumbnail    
// Remember, first thumbnail should be largest thumbnail    
$img_s1 = imagecreatetruecolor($s1_w, $s1_h);    
imagecopyresampled($img_s1, $src, 0, 0, 0, 0, $s1_w, $s1_h, $w, $h);    
imagedestroy($src); 
// Destroy source image     
// Other thumbnails are just downscaled copies of the first one    
for($i=1; $i<sizeof($params); $i++)    {        
list($cur_w, $cur_h) = thumbnail_calcsize($w, $h, $params[$i]['size']);        
$img_cur = imagecreatetruecolor($cur_w, $cur_h);        
imagecopyresampled($img_cur, $img_s1, 0, 0, 0, 0, $cur_w, $cur_h, $s1_w, $s1_h);        
imagejpeg($img_cur, $params[$i]['file'], 90);        
imagedestroy($img_cur);    }    // Saving first thumbnail     
imagejpeg($img_s1, $params[0]['file'], 90);    
imagedestroy($img_s1);    
return true;}

// Upload processing part: 
if (isset($_FILES['file']) && ($_FILES['file']['size'] > 0))
{    
$u_filename = basename($_FILES['file']['name']);   
move_uploaded_file($_FILES['file']['tmp_name'], "/upload/" . $_FILES['file']['name']);    
// Setting params array for thumbnail_generator     
$params = array(array('size' => 220,                          
'file' => $upload_dir.'/s1-'.$u_filename),                    
array('size' => 140,                          
'file' => $upload_dir.'/s2-'.$u_filename),                    
array('size' => 80,                          
'file' => $upload_dir.'/s3-'.$u_filename));    
if (thumbnail_generator($upload_dir.'/'.$u_filename, $params) == false)
die("Error processing uploaded file {$u_filename}");    
// ok, redirecting     
// same host (HTTP_HOST), same script (PHP_SELF)    
// add ?file=filename parameter    
header("Location: http://{$_SERVER['HTTP_HOST']}{$PHP_SELF}?file={$u_filename}");    
exit();}
// Upload processing end ?> 
<html><head> 
<title>PHP multiple thumbnail generator</title> 
</head><body> 
<?php if (!isset($_GET['file'])) {// Following HTML code is outputed when user just loads this page?> 
<h1>Upload image:</h1> 
<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data"> 
<script type="text/javascript"> /* This function is called when user selects file in file dialog */ 
function checkext(upload_field) {     
// this is just an example of checking      
// image file extension - jpg/jpeg     
var re_text = /\.jpeg|\.jpg/i;     
var filename = upload_field.value;     
/* Checking file type */     
if (filename.search(re_text) == -1)     
{ alert("Please select JPEG file");         
upload_field.value = ''; }     
return true; } 
</script> 
Select jpeg photo: <input type="file" name="file" id="file" onChange="return checkext(this)"> <br><br><input type="submit"  value="upload & generate thumbnails"> </form> 
<?php
}else {
// And this HTML code is shown when image was uploaded
$file = $_GET['file'];?> <h1>Photo: <?php echo $file; ?>
</h1> <div align="center"> <!-- Outputting thumbnails -->
<img src="<?php echo $web_upload_dir.'/s1-'.$file; ?>"> 
<img src="<?php echo $web_upload_dir.'/s2-'.$file; ?>"> 
<img src="<?php echo $web_upload_dir.'/s3-'.$file; ?>"> <br><br> <!-- Outputting uploaded photo -->
<img src="<?php echo $web_upload_dir.'/'.$file; ?>"> </div> <?php
}?> <br><br><br> Example by <a href="http://www.anyexample.com/">AnyExample</a> </body> </html>?>

everytime i get the following error

Warning: move_uploaded_file(/upload/banner.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in E:\xampp\htdocs\gd_upload.php on line 59

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'E:\xampp\tmp\php13.tmp' to '/upload/banner.jpg' in E:\xampp\htdocs\gd_upload.php on line 59
Error processing uploaded file banner.jpg

 

i have created "upload" folder in  E:/Xampp/htdocs

 

i have amended this in that script

$upload_dir = "e:/www/htdocs/upload"; 

 

 

vineet

 

Link to comment
https://forums.phpfreaks.com/topic/167953-gd-script-showing-error/
Share on other sites

I would venture to say it has something to do with the path you're trying to use.  I would think that since you appear to be on a Windows box, the path you'd want to move the file to would need to either be relative (upload/banner.jpg without the leading /) or full including the drive letter before the path.

hi patrick

 

if i change

move_uploaded_file($_FILES['file']['tmp_name'], "/upload/" . $_FILES['file']['name']);  

 

to

move_uploaded_file($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']['name']);  

 

then i get error

Error processing uploaded file banner.jpg
whether i remove the slash from front or slash from back of "upload" i get the same error.

 

vineet

 

I would venture to say it has something to do with the path you're trying to use.  I would think that since you appear to be on a Windows box, the path you'd want to move the file to would need to either be relative (upload/banner.jpg without the leading /) or full including the drive letter before the path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.