[RESOLVED] I have a problem with my move_uploaded_file
I have been trying to de-bug my thumb creator.
It runs without out error but it is not placing any image into the destination directory.
Can you please help me de-bug it - can you see any error or what should I insert to debub it ?
You will see that I have 2 debud lines and they display expected data.
here is the script:
PHP Code:
function makeThumbnail ( $source , $t_ht , $N_pix_n ) {
$image_info = getImageSize ( $source ) ; // see EXIF for faster way
echo print_r ( $image_info );
switch ( $image_info [ 'mime' ]) {
case 'image/gif' :
if ( imagetypes () & IMG_GIF ) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF ( $source ) ;
} else {
$ermsg = 'GIF images are not supported<br />' ;
}
break;
case 'image/jpeg' :
if ( imagetypes () & IMG_JPG ) {
exec ( ":d/web/jhead -purejpg " . $source ); // cleans up jpg headers
$o_im = imageCreateFromJPEG ( $source ) ;
} else {
$ermsg = 'JPEG images are not supported<br />' ;
}
break;
case 'image/png' :
if ( imagetypes () & IMG_PNG ) {
$o_im = imageCreateFromPNG ( $source ) ;
} else {
$ermsg = 'PNG images are not supported<br />' ;
}
break;
case 'image/wbmp' :
if ( imagetypes () & IMG_WBMP ) {
$o_im = imageCreateFromWBMP ( $source ) ;
} else {
$ermsg = 'WBMP images are not supported<br />' ;
}
break;
default:
$ermsg = $image_info [ 'mime' ]. ' images are not supported<br />' ;
break;
} // end switch
IF (!isset( $ermsg )) {
$o_wd = imagesx ( $o_im ) ;
$o_ht = imagesy ( $o_im ) ;
// thumbnail width = target * original width / original height
$t_wd = round ( $t_ht * $o_wd / $o_ht ) ;
if( imageistruecolor ( $o_im )){
$N_image = @ imagecreatetruecolor ( $t_wd , $t_ht ) or die( 'Invalid resize dimmensions' );
imageAlphaBlending ( $N_image , false ); // this disabled so that saveAlpha can be used.
imageSaveAlpha ( $N_image , true );
}
else{
$N_image = @ imagecreate ( $t_wd , $t_ht ) or die( 'Invalid resize dimmensions' );
if( false !== ( $trans = @ imagecolorsforindex ( $source , imagecolortransparent ( $source )))){
$trans = ImageColorAllocate ( $N_image , $trans [ 'red' ], $trans [ 'green' ], $trans [ 'blue' ]);
imagefilledrectangle ( $N_image , 0 , 0 , $w - 1 , $h - 1 , $trans );
imagecolortransparent ( $N_image , $trans );
}
} // end else
echo " $t_wd , $t_ht , $o_wd , $o_ht " ;
imagecopyresampled ( $N_image , $o_im , 0 , 0 , 0 , 0 , $t_wd , $t_ht , $o_wd , $o_ht );
imageJPEG ( $N_image , $N_pix_n , 80 );
imageDestroy ( $o_im );
imageDestroy ( $N_image );
} // end IF
return (isset( $ermsg )? $ermsg : NULL );
} // End of Function
IF (isset( $_POST [ 'run_mn' ])){
$N_pix1 = strip_tags ( trim ( $_FILES [ 'upLoad1' ][ "name" ]));
if( $N_pix1 != "" ){
if( $_FILES [ 'upLoad1' ][ 'tmp_name' ] == "none" ) {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K" ;
require_once ( "a_picts_fm.php" );
exit();
} // endif
if(! ereg ( "image" , $_FILES [ 'upLoad1' ][ 'type' ])) {
$message1 = "The file you have selected for Picture 1 is not" ;
$message2 = "a recognised picture file - Please try a different file" ; require_once ( "a_picts_fm.php" );
exit();
} // endif
$pix1_y = "y" ;
} // endif
else{
$N_pix1 = "none" ;
} // end else
/*
* Everything seems ok - so we create the thumbnails from the temp_files.
*/
$ad_ref = 5 ;
if( $pix1_y == "y" ){
$image = $_FILES [ 'upLoad1' ][ 'tmp_name' ];
$N_pix1 = makeThumbnail ( $image , 120 , $N_pix1 );
$N_pix1 = time (). "-" . $N_pix1 . "_small" ;
$destination = 'D:\Web\images' . "\\" . $N_pix1 ;
move_uploaded_file ( $N_pix_n , $destination );
require_once( "Letter_yod.inc" );
$connection = mysql_connect ( $host , $user , $password )
or die ( "Couldn't connect to server." );
$db = mysql_select_db ( $database , $connection )
or die ( "Couldn't select database." );
$sql = "UPDATE events SET image1 = ' $N_pix1 '
WHERE ad_ref = ' $ad_ref ' " ;
mysql_query ( $sql ) or die( "could not execute events UPDATE PICTURES query" );
} // endif
} // end BIG IF
ELSE {
include_once( "z_resize_fm.php" );
exit();
} // end ELSE
and this is the form:
PHP Code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > < html >
< head >
< title > Untitled </ title >
</ head >
< body >
< div style = 'width:600px; position:absolute; left:200px; top:400px' >
< form name = "main_fm" enctype = "multipart/form-data" action = "z_resize.php" method = "POST" >
< input type = "hidden" name = "run_mn" value = "yes" /> < input type = "file" size = "50" id = "u1" name = "upLoad1" >
< br />
< input type = "submit" Value = "Upload" >
</ div >
</ body >
</ html >
Thanks for any help.
Try starting your script with error_reporting(E_ALL); so that any and all notices and warnings from the PHP processor are displayed.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in
Nation
eBookworm.us
if you got any error message go to php.ini file ennter new line error_log = c:/log.txt;
Then restart the server now you will get the error mesage log.txt.
Thanks
Vssp
Thanks
that has helped - I got this notice:
Notice: Undefined variable: N_pix_n in D:\Web\Yod\z_resize.php on line 105
I have made some changes and ...
...I am now getting an image with the correct name ...but not at the destination !
the image 1155209519-small-Ginger.JPG (origional image name Ginger.JPG)
is on the same directory as the program and not in D:\Web\images.
My new script is: ( no errors reported )
PHP Code:
error_reporting ( E_ALL );
function makeThumbnail ( $source , $t_ht , $N_pix_n ) {
$image_info = getImageSize ( $source ) ; // see EXIF for faster way
echo print_r ( $image_info );
switch ( $image_info [ 'mime' ]) {
case 'image/gif' :
if ( imagetypes () & IMG_GIF ) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF ( $source ) ;
} else {
$ermsg = 'GIF images are not supported<br />' ;
}
break;
case 'image/jpeg' :
if ( imagetypes () & IMG_JPG ) {
exec ( ":d/web/jhead -purejpg " . $source ); // cleans up jpg headers
$o_im = imageCreateFromJPEG ( $source ) ;
} else {
$ermsg = 'JPEG images are not supported<br />' ;
}
break;
case 'image/png' :
if ( imagetypes () & IMG_PNG ) {
$o_im = imageCreateFromPNG ( $source ) ;
} else {
$ermsg = 'PNG images are not supported<br />' ;
}
break;
case 'image/wbmp' :
if ( imagetypes () & IMG_WBMP ) {
$o_im = imageCreateFromWBMP ( $source ) ;
} else {
$ermsg = 'WBMP images are not supported<br />' ;
}
break;
default:
$ermsg = $image_info [ 'mime' ]. ' images are not supported<br />' ;
break;
} // end switch
IF (!isset( $ermsg )) {
$o_wd = imagesx ( $o_im ) ;
$o_ht = imagesy ( $o_im ) ;
// thumbnail width = target * original width / original height
$t_wd = round ( $t_ht * $o_wd / $o_ht ) ;
if( imageistruecolor ( $o_im )){
$N_image = @ imagecreatetruecolor ( $t_wd , $t_ht ) or die( 'Invalid resize dimmensions' );
imageAlphaBlending ( $N_image , false ); // this disabled so that saveAlpha can be used.
imageSaveAlpha ( $N_image , true );
}
else{
$N_image = @ imagecreate ( $t_wd , $t_ht ) or die( 'Invalid resize dimmensions' );
if( false !== ( $trans = @ imagecolorsforindex ( $source , imagecolortransparent ( $source )))){
$trans = ImageColorAllocate ( $N_image , $trans [ 'red' ], $trans [ 'green' ], $trans [ 'blue' ]);
imagefilledrectangle ( $N_image , 0 , 0 , $w - 1 , $h - 1 , $trans );
imagecolortransparent ( $N_image , $trans );
}
} // end else
echo "<br> $t_wd , $t_ht , $o_wd , $o_ht " ;
imagecopyresampled ( $N_image , $o_im , 0 , 0 , 0 , 0 , $t_wd , $t_ht , $o_wd , $o_ht );
echo "<br>N_image: $N_image . - N_pix_n: $N_pix_n ." ;
imageJPEG ( $N_image , $N_pix_n , 80 );
imageDestroy ( $o_im );
imageDestroy ( $N_image );
} // end IF
return (isset( $ermsg )? $ermsg : NULL );
} // End of Function
IF (isset( $_POST [ 'run_mn' ])){
$N_pix1 = strip_tags ( trim ( $_FILES [ 'upLoad1' ][ "name" ]));
if( $N_pix1 != "" ){
if( $_FILES [ 'upLoad1' ][ 'tmp_name' ] == "none" ) {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K" ;
require_once ( "a_picts_fm.php" );
exit();
} // endif
if(! ereg ( "image" , $_FILES [ 'upLoad1' ][ 'type' ])) {
$message1 = "The file you have selected for Picture 1 is not" ;
$message2 = "a recognised picture file - Please try a different file" ; require_once ( "a_picts_fm.php" );
exit();
} // endif
$pix1_y = "y" ;
} // endif
else{
$N_pix1 = "none" ;
} // end else
/*
* Everything seems ok - so we create the thumbnails from the temp_files.
*/
$ad_ref = 5 ;
if( $pix1_y == "y" ){
$image = $_FILES [ 'upLoad1' ][ 'tmp_name' ];
$N_pix1 = time (). "-small-" . $N_pix1 ;
$N_pict = makeThumbnail ( $image , 120 , $N_pix1 );
$destination = 'D:\Web\images' . "\\" . $N_pix1 ;
move_uploaded_file ( $N_pict , $destination );
require_once( "Letter_yod.inc" );
$connection = mysql_connect ( $host , $user , $password )
or die ( "Couldn't connect to server." );
$db = mysql_select_db ( $database , $connection )
or die ( "Couldn't select database." );
$sql = "UPDATE events SET image1 = ' $N_pix1 '
WHERE ad_ref = ' $ad_ref ' " ;
mysql_query ( $sql ) or die( "could not execute events UPDATE PICTURES query" );
} // endif
} // end BIG IF
ELSE {
include_once( "z_resize_fm.php" );
exit();
} // end ELSE
the ouput is :
Array ( [0] => 1024 [1] => 768 [2] => 2 [3] => width="1024" height="768" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) 1
160, 120, 1024, 768
N_image:Resource id #6. - N_pix_n:1155209519-small-Ginger.JPG.
And I found the image - a small 160 by 120 (great!
but not at destination.
Do you think that the MOVE has happened or is the found image the created one ?
Maybe these lines were not acted on ?
$destination = 'D:\Web\images'."\\".$N_pix1;
move_uploaded_file($N_pict,$destination);
Any thoughts ??
Thanks - getting there
OK - thanks for your help.
I solved this - the move... isn't necassary I just need to create it in the directory straight off.
So I moved the destination into the function:
PHP Code:
$destination = 'D:\Web\images' . "\\" . $N_pix_n ;
imageJPEG ( $N_image , $destination , 80 );
imageDestroy ( $o_im );
imageDestroy ( $N_image );
And it works fine !
Result - thumbs without any uploaded images !
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks