Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/147846-solved-img-database-upload/
Share on other sites

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);

 

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??

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.