I have this script i made.
SQL:
And heres the imageupload
Basicly i uploads the image file to temp/ folder. gets the binary and saves it in the mysql folder (as well as creates a thumbnail and saves that into the sql as well)
But if you upload a png image it don't seem to display.
http://rmb-scripting.com/rmb-space/userdata/picture/1/ Thats a png (as you can see it wont display)
http://rmb-scripting.com/rmb-space/userdata/picture/2/ Gif works fine
http://rmb-scripting.com/rmb-space/userdata/picture/2/ jpg works fine
Also with the thumbnail maker it don't work when making a thumbnail for jpg.
This is the error i get
I hope you can help on these 2 problems.
Thanks,
Daniel
SQL:
| Code: |
| CREATE TABLE `pictures` (
`id` int(11) NOT NULL AUTO_INCREMENT, `pfl_id` varchar(100), `pic_title` varchar(50), `pic_desc` varchar(50), `pic_format` varchar(5), `pic_width` int(11), `pic_height` int(11), `content` BLOB, `thumb_content` BLOB, PRIMARY KEY (`id`) ) TYPE = MYISAM; |
And heres the imageupload
| Code: |
| <?php
include("header.php"); if(!$account[id]) { header("Location: " . $siteurl); }else if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { if(substr($HTTP_POST_FILES['userfile']['type'],0,5) == image) { $pic_format = explode("/", $HTTP_POST_FILES['userfile']['type']); $vcode = gencode("32"); $filename = "temp/" . $vcode . "." . $pic_format[1]; if(@copy($_FILES['userfile']['tmp_name'], $filename)) { $PSize = filesize($filename); $contents = addslashes(fread(fopen($filename, "r"), $PSize)); list($width, $height, $type, $attr) = getimagesize($filename); //Create thumbnail if($pic_format[1] == "gif") { $im=ImageCreateFromgif($filename); }elseif($pic_format[1] == "png") { $im=ImageCreateFrompng($filename); }elseif($pic_format[1] == "jpg") { $im=ImageCreateFromjpeg($filename); } $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($thumb_width,$thumb_height); imageCopyResized($newimage,$im,0,0,0,0,$thumb_width,$thumb_height,$width,$height); $filename_thumb = "temp/thumb_" . $vcode . "." . $pic_format[1]; if (function_exists("imagegif")) { Imagegif($newimage,$filename_thumb); }elseif (function_exists("imagejpeg")) { ImageJPEG($newimage,$filename_thumb); }elseif (function_exists("imagepng")) { Imagepng($newimage,$filename_thumb); } $PSize_thumb = filesize($filename_thumb); $contents_thumb = addslashes(fread(fopen($filename_thumb, "r"), $PSize_thumb)); //finished creating thumbnail $insert = mysql_query("INSERT INTO `pictures` (`pfl_id`,`pic_title`,`pic_desc`,`pic_format`,`pic_width`,`pic_height`,`content`,`thumb_content`) VALUES ('" . $account[id] . "','" . protect($_POST[pic_title]) . "','" . protect($_POST[pic_desc]) . "','" . protect($pic_format[1]) . "','" . $width . "','" . $height . "','" . $contents . "','" . $contents_thumb . "')"); unlink($_SERVER["DOCUMENT_ROOT"] . $prefix . "/temp/" . $vcode . "." . $pic_format[1]); unlink($_SERVER["DOCUMENT_ROOT"] . $prefix . "/temp/thumb_" . $vcode . "." . $pic_format[1]); if($insert) { $msgtitle = "Success"; $message = "Image uploaded."; }else{ $msgtitle = "Unknown Error"; $message = "Image could not be inserted in the database.<br />If this continues to happern please report this."; } }else{ $msgtitle = "Unknown Error"; $message = "Image could not be uploaded.<br />If this continues to happern please report this."; } }else{ $msgtitle = "Error"; $message = "File must be a image."; } ?> <table cellspacing="0"> <tr> <td class="cleft"> <table class="tb" id="spa"> <tr> <td class="bar"><?=$msgtitle?></td> </tr> <tr> <td class="panel"><?=$message?></td> </tr> </table> </td> <td class="cright" width="200" align="center"><? include("advert2.php"); ?></td> </tr> </table> <? }else{ ?> <table cellspacing="0"> <tr> <td class="cleft"> <table class="tb" id="spa"> <tr> <td class="bar">Upload Picture</td> </tr> <tr> <td class="panel"><form method="post" enctype="multipart/form-data"> <table> <tr> <td>File:</td> <td><input type="file" name="userfile" size="45" /></td> </tr> <tr> <td>Image Title:</td> <td><input type="text" style="width:250px;" name="pic_title" /></td> </tr> <tr> <td valign="top">Image Description:</td> <td><textarea style="width:450px;" name="pic_desc"></textarea></td> </tr> <tr> <td colspan="2"><input type="submit" value="Upload" onclick="this.value='Uploading...'"></td> </tr> </table> </form></td> </tr> </table> </td> <td class="cright" width="200" align="center"><? include("advert2.php"); ?></td> </tr> </table> <? } include("footer.php"); ?> |
Basicly i uploads the image file to temp/ folder. gets the binary and saves it in the mysql folder (as well as creates a thumbnail and saves that into the sql as well)
But if you upload a png image it don't seem to display.
http://rmb-scripting.com/rmb-space/userdata/picture/1/ Thats a png (as you can see it wont display)
http://rmb-scripting.com/rmb-space/userdata/picture/2/ Gif works fine
http://rmb-scripting.com/rmb-space/userdata/picture/2/ jpg works fine
Also with the thumbnail maker it don't work when making a thumbnail for jpg.
This is the error i get
| Quote: |
|
Warning: imagesx(): supplied argument is not a valid Image resource in /home/rmb/public_html/rmb-space/uploadphoto.php on line 23 Warning: imagesy(): supplied argument is not a valid Image resource in /home/rmb/public_html/rmb-space/uploadphoto.php on line 24 Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/rmb/public_html/rmb-space/uploadphoto.php on line 26 |
I hope you can help on these 2 problems.
Thanks,
Daniel
