Hello
I am making a classifieds site. I have a form that the user fills in to post an advert, and one of the fields is an image upload. I have used a script that i found online to process the image upload, and create thumbnails for the images.
I want to make it so if the user does not upload an image, a default "no image" picture is shown. Here is the script:
$n_width=100; // Fix the width of the thumb nail images
$tsrc="thimg/".$_FILES[userfile][name]; // Path where thumb nail image will be stored
//////////// Starting of GIF thumb nail creation///////////
if (@$_FILES[userfile][type]=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$ratio= $width / 100;
$n_height= $height / $ratio;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}////////// end of gif file thumb nail creation//////////
////////////// starting of JPG thumb nail creation//////////
if($_FILES[userfile][type]=="image/jpeg"){
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$ratio= $width / 100;
$n_height= $height / $ratio;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
I want to make it so if the user does not upload an image, the value which is strored in the database is the path upimg/no_image.gif & thbimg/no_img.gif
I have tried by setting the default value in the database, but this obviously gets overwritten by the script, and makes the image path "upimg/" and "thbimg/"
I need to put in some sort of "if" statement, but I just can't seem to get it right! please help!
I am making a classifieds site. I have a form that the user fills in to post an advert, and one of the fields is an image upload. I have used a script that i found online to process the image upload, and create thumbnails for the images.
I want to make it so if the user does not upload an image, a default "no image" picture is shown. Here is the script:
$n_width=100; // Fix the width of the thumb nail images
$tsrc="thimg/".$_FILES[userfile][name]; // Path where thumb nail image will be stored
//////////// Starting of GIF thumb nail creation///////////
if (@$_FILES[userfile][type]=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$ratio= $width / 100;
$n_height= $height / $ratio;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}////////// end of gif file thumb nail creation//////////
////////////// starting of JPG thumb nail creation//////////
if($_FILES[userfile][type]=="image/jpeg"){
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$ratio= $width / 100;
$n_height= $height / $ratio;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
I want to make it so if the user does not upload an image, the value which is strored in the database is the path upimg/no_image.gif & thbimg/no_img.gif
I have tried by setting the default value in the database, but this obviously gets overwritten by the script, and makes the image path "upimg/" and "thbimg/"
I need to put in some sort of "if" statement, but I just can't seem to get it right! please help!