ambo Posted March 4, 2009 Share Posted March 4, 2009 Ok for some of you who may have helped me on a previous post thank you but im still not getting this script to upload now the resize seems to work fine but the sql wont submit <?php // Connect to database include("dbconnect.php"); $user=$_POST['userimgnm']; // This is the temporary file created by PHP $uploadedfile = $_FILES['userfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=200; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $sql = "UPDATE images SET name='$fileName', size='$fileSize', type='$fileType', content='$content' WHERE id = '$user' LIMIT 1"; mysql_query($sql) or die('Error, query failed'); } echo "<br>File $fileName uploaded<br>"; echo "$sql"; ?> When i submit the data gives me a bunch of shreded text that is the image blob but it wont update the database Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/ Share on other sites More sharing options...
samshel Posted March 4, 2009 Share Posted March 4, 2009 mysql_query($sql) or die('Error, query failed'); change to mysql_query($sql) or die(mysql_error()); and it will show u what the problem is with the query. Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-775985 Share on other sites More sharing options...
ambo Posted March 4, 2009 Author Share Posted March 4, 2009 ill have to try that Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776294 Share on other sites More sharing options...
ambo Posted March 4, 2009 Author Share Posted March 4, 2009 I Get NO errors but the image doestn upload?? still it says file uploaded but there is no file there Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776447 Share on other sites More sharing options...
premiso Posted March 4, 2009 Share Posted March 4, 2009 Have you printed out the variables (all but the image $content) and see if they hold the right items? My bet would be $user is either not valid or not being passed through. And : if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } Is sort of backwards. I would recommend this: if (get_magic_quotes_gpc()) { $fileName = stripslashes($fileName); } $fileName = mysql_real_escape_string($fileName); Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776471 Share on other sites More sharing options...
ambo Posted March 4, 2009 Author Share Posted March 4, 2009 when i hit post i see something like this 5Zøš±§ºiߟ™[ÞøwÚI¿{“ú<°ÿ‚ŸüRñÖ¡â‡þøc>¥ûBZøYt+x*ÂTø#àBÛWŽi&ñÔ|d|{Ã$—í¦Ûݸ·Ô´ #ó Ó'ç‡|3áíGâ…¯…´kÙõ…¿³dO¶¹©´Rj:ßµËÛˆšwŠõ¹â±¹“ÃSêzÞ“gqga¥O1k¹Ä·’ø¿…à¢vŸ ¼ «[øÏàý惮xFSφ¡ÔõX5&´‚)¾Ó©Ébò4·¢ä—Š6mãbK¢ú¿‡$øsû1|AÑ.Ò]GY?üuªëòÛ‰Zïûr}?\½Ñ$TA´ðéWpG $Œ£t2àL„<ú(`~¼UšqF3,Á`òì,+J¯ÕéJ0¯‰¥ ´©ÍóÊP„)BsTU:TÔç+9M³ýñ#Æ>㌋"Ãð¶%ÒÌ3ü]*Q§%:T*N’T¤“Rm)¥+Ý»k³¿Ð²fkªÚ|Rø«¨\B.~(øt[˜å.`Ólþk~,ÑtÛËòÚHŸV¶ÔÍÌ=ÍâÊñDÉ ’‰þ±ŽÖimì%šúÆ=Bè ¢CK`ÈáQ<¦6íMÛ˜îãðMÆÞ ø%ð«á½‹¼¤x^Úÿ¾Öô]î´¿¿¾Õt'TÕVx5{‹[Ñ!ºÔlÌ‹ “í7-òF¾ZºŸÚgàÞ¥|ï«kÑè7RF³A}w¥ØéŒå'K‰õx v”ò™²l²íþ{ãœV?‰üDâÌç)KR¼þ«ß,TjGHôø~ëôÐþÖðò…àÌ£!pK_ F¾*v\Ò•TäÞ·këÓcßíCݳǫO匵ˮåeäÀƒóŽ©‘îjh%–#òOsm '2Bʬ',| £Ž9Æk•ð÷ˆü=ñ7„5ŸxîÖÔ'½Òé_Ù‰$wI©xSÅSx¥üEmö§º„[ÝYø”ؤ墙Œn¦Â O'Ý:ÕìZo‡õëÙ0ËFÕn’ ½…ÄÈNN VAœþ>•ð‡ìý¼ðF£ã Z_KãbøaæmZhèdã †6§ cê¾?¢~<;.$âÙbªÓ^ÏZ*¶ž÷,®´òé§ëüƒô¶ãHp÷ PÁaåìå¡_m/ËîùmO½žãß\x[Â~>ñµÖÙ/<á[]KX÷+™t1¯¢¶¶F–9ËÏåÚ÷©rø•v³§âð§ÃÍ"]V3yâ zäøËVט‡Ôu™|MuâO Zk“4p¬Úo…!Ôÿ³íc·….-ôï6$¸¼—çÿÚb¸øw%”Òyšïˆ¬tíYÿ…t‹½+U‚ôÈÄ.-Š¥äÝÐÞ˜Éû—A’üx{E:|Q¥ºøgÁVŠeUtÝ?Eµ¶šë>\Ÿ»[uóÚbv„ùÚ@¹5úwÒë‰1¸G‡á춬©¾XÓJ.×I%{.ß;=t̾†<)ƒÅûn%̩¢çuy¦“Ó}Ýõi›“ÜÜ4÷wÓj·-ªæ†îîÖQË!ó,4ö–"Ã@…ä•tØî¯ÞF<„^ÑfûèiÝhÿ¯ëü‚ž~ž}z~”Ê+,D#Š·Öµ¶Üúì7+öþ~ßÕõ%óN1Œ}ÈTMó““Û?¦3ן^ôQYÇ B<¶§Ëðé¶ßåø°„åNJP÷dÓ[Ý[ü¿«+"ŽÎKA5»+€ñ´s¦Ç&3ò—ÇÝr7!'i§«&%»9¦Q$‘UM‹+‚ë*`„Œd šmÙ:õgKØÎnTð;rÛÒÞFë‰rMUŸ5ÕÚiì¶Ûþ ,i¾·ñŒ¾|=¹x§xJ—¡h¨-/{)=[3®t_Ig&©á¯ ëGO±‡MÓÓ[ðö“«Eekoi¤1ÚEi:[‚4"6[;¢Bµ×Áþ‘ÁŸÁ¾¸"Oá}hÕy@‚9,]j Ø€mSÊ]9„`ò:{äqéŽsÔ‚¥~$þ‡üýzõ¯ó‚8¬E¹´èV+ÚIBVi¹FîÞ¶?ÕLv:ySxzNÔãI¾]y!˦یZº¾ÎéXò]/ীô¿Š´m[bÔ% Ig¢kš–‘¢H °ÊUô=>{}1Ô´nSlAD ~Zõ¦*"3E0ùr²$1$qì —Äqª¢³…/#…Üò3;#'ÿ«ñÎ==iñÇ =/#sì1å¯ÓïsœcžÜÖ¶êÂJžo•¹KWv£¾îúv//§‡^Ú1§T¥dÖß ¿ÊÝïÝžKñÿ[ÿ„káuÈ%ÛDÓáfÃ7ˆ¯´[ KÉ“íá#3°(U¾aó÷Â*MáOÃMaHì¼?¤èÓ#cØílCƌij™DÀ˜“#p ÷¶-ĉû8xæÞ7+,'øSm¼1Äÿ¼%¨ Ž=ê@8*H ‚sjÆÖËû>5šQ¸($cÊO*1Ó¨¯ï I did notice that it should post the File Name because if echo "<br>File $fileName uploaded<br>"; And at the end i see File Uploaded but the image doesnt change Any Thoughts?? Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776478 Share on other sites More sharing options...
premiso Posted March 4, 2009 Share Posted March 4, 2009 Well you are echoing $sql, which echos that whole statement. I would avoid doing that, just because of the binary data. What do you mean "the image doesn't change". You will not be able to access the image on that page directly, as it has to have the correct headers. You would need another script to fetch the recently inserted image from the $user IE: echo "<img src='image.php?id={$user}>"; Where the image.php script retrieves an image from the mysql database at that id and uses header call to print out the actual image. Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776484 Share on other sites More sharing options...
ambo Posted March 4, 2009 Author Share Posted March 4, 2009 I know thats what i mean the image on there profile page which calls that doesnt call a different picture as well as the data for that row in the data base doesnt change Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776606 Share on other sites More sharing options...
premiso Posted March 4, 2009 Share Posted March 4, 2009 Back to my original theory. $user=$_POST['userimgnm']; That line is not populating $user correctly. Try printing it out and see if that is what you expect. If it is not there is your issue. Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-776643 Share on other sites More sharing options...
ambo Posted March 5, 2009 Author Share Posted March 5, 2009 The user Was being Printed.. i found the problem if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { The $_POST ['upload'] my submit button was imgupload so i changed to $_POST ['imgupload'] And it worked Quote Link to comment https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/#findComment-777205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.