illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 i've read the whole thread.. i'm gonna try to fix your code or look into it but since you are using mysql to store images my first question if would work with images i would ask somewhere or here on phpfreaks what would be the best solution for storing images for a gallery or something similar. and everyone would answer me the same thing a folder on hdd no database in the end my advice is use folders to store images and mysql to store their for outputting them on your site. P.S i think everyone will agreed with me I found this out after I used this method, too lazy to switch now. I won't be uploading mass amounts of images, or for that matter really putting huge loads on the DB. Just trying to figure out why the upload form rejects .jpg's or .png's. Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-840956 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 Might anyone know why my database doesn't like jpeg's or any other file rather than the .gif? Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841010 Share on other sites More sharing options...
hitman6003 Posted May 24, 2009 Share Posted May 24, 2009 what is the header you are sending to the browser? Is it hard coded to gif? Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841011 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 <? if(isset($_REQUEST['id'])) { // get the file with the id from database include 'connect.php'; $id = $_REQUEST['id']; $query = "SELECT `img_name`, `img_type`, `img_size`, `img_data` FROM img_tbl WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error()); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); print $content; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841023 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 Hmm, that's odd. Still can't seem to figure this one out. ??? Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841236 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 to do have this on a live server ? P.S i think everyone will agreed with me Well it really does depends, but yeah by defaut i would go for file and folder, but their have been cases where a database blob was better. Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841241 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 to do have this on a live server ? P.S i think everyone will agreed with me Well it really does depends, but yeah by defaut i would go for file and folder, but their have been cases where a database blob was better. Yes, it's on a live server. Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841270 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 if you send me a link (PM if you want) i'll take a look at the outputs Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841273 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 Techie you get my PM? Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841282 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 got it, ID 13 works fine, you got some other id's i can test, (jpegs, or even the link to upload) Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841307 Share on other sites More sharing options...
illusive101 Posted May 24, 2009 Author Share Posted May 24, 2009 The place I upload it is a secured backend, however I can give you the login information. Do you have some sort of messenger that culd speed this up? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841348 Share on other sites More sharing options...
fantomel Posted May 25, 2009 Share Posted May 25, 2009 to do have this on a live server ? P.S i think everyone will agreed with me Well it really does depends, but yeah by defaut i would go for file and folder, but their have been cases where a database blob was better. it's good to know that sometimes it's better usign blob Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-841620 Share on other sites More sharing options...
illusive101 Posted May 28, 2009 Author Share Posted May 28, 2009 Unbelievable I still can't figure out why this won't take my .jpeg's! If anyone can help, please do! // Loading images into Database if(isset($_REQUEST[submit]) && $_FILES[imgfile][size] > 0) { $fileName = $_FILES[imgfile][name]; // image file name $tmpName = $_FILES[imgfile][tmp_name]; // name of the temporary stored file name $fileSize = $_FILES[imgfile][size]; // size of the uploaded file $fileType = $_FILES[imgfile][type]; // file type $fp = fopen($tmpName, 'r'); // open a file handle of the temporary file $imgContent = fread($fp, filesize($tmpName)); // read the temp file fclose($fp); // close the file handle $query = "INSERT INTO img_tbl (`img_name`, `img_type`, `img_size`, `img_data` ) VALUES ('$fileName', '$fileType', '$fileSize', '$imgContent')"; mysql_query($query) or die('Error, query failed'); $imgid = mysql_insert_id(); // autoincrement id of the uploaded entry echo "<br>Image successfully uploaded to database<br>"; }else die('You have not selected any image'); // End loading image When I try to upload it I get Error, query failed. Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844377 Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi Change the query line to mysql_query($query) or die('Error, query failed '.mysql_error()); just to check what the error message is. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844383 Share on other sites More sharing options...
illusive101 Posted May 28, 2009 Author Share Posted May 28, 2009 Hi Change the query line to mysql_query($query) or die('Error, query failed '.mysql_error()); just to check what the error message is. All the best Keith Error, query failed You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 Line 2 in that file is below: <html xmlns="http://www.w3.org/1999/xhtml"> Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844407 Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi Think you need to use addslashes on $imgContent before you insert it. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844412 Share on other sites More sharing options...
illusive101 Posted May 28, 2009 Author Share Posted May 28, 2009 hmm, how would I go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844420 Share on other sites More sharing options...
thebadbad Posted May 28, 2009 Share Posted May 28, 2009 Or more appropriately mysql_real_escape_string(), and on all variables: $query = sprintf( "INSERT INTO `img_tbl` (`img_name`, `img_type`, `img_size`, `img_data`) VALUES ('%s', '%s', '%s', '%s')", mysql_real_escape_string($fileName), mysql_real_escape_string($fileType), mysql_real_escape_string($fileSize), mysql_real_escape_string($imgContent) ); Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844423 Share on other sites More sharing options...
illusive101 Posted May 28, 2009 Author Share Posted May 28, 2009 bad, thank you very much! That fixed the problem. One last thing, does anyone know how to load the image into a template? As in have the image loaded from the database to display on a page and have a "border" around it per say. However, the border must be a image I made saved as a .png so the middle of it is seethrough where the image I uploaded load's. Sounds confusing, but if anyone knows I'd GREATLY appreciate it. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844439 Share on other sites More sharing options...
thebadbad Posted May 28, 2009 Share Posted May 28, 2009 You should use a script that outputs the image data with the proper header; let's call it image.php: <?php $name = $_GET['name']; //here you connect to the database and retrieve image type ($type) and data ($data) based on the filename from above (or preferably an ID, if possible) //define allowed headers (image types) $headers = array('image/gif', 'image/jpeg', 'image/png'); //set header header('Content-type: ' . $headers[array_search($type)]); //output image data echo $data; ?> And then produce the image in your HTML via image.php?name=imagename. To get the border thingy going, you can arrange one div on top of another, the bottom one holding the 'real' image, and the one in the front holding the border image. Utilizing CSS all the way. Quote Link to comment https://forums.phpfreaks.com/topic/159344-unexpected-t_variable/page/2/#findComment-844491 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.