jcg Posted May 23, 2012 Share Posted May 23, 2012 Hi all, Instead of image, always gives empty square with red cross!!!! :'( why???? I've tried everything... other ways, other foruns, ... I'm getting crazy!!!!! will not have to do with the Apache server? I can not visualize the temporary file on the server, for example "var/www/html/images/phpmYEYF9" i use a trick...i copy the tmp file "var/www/html/images/phpmYEYF9" that i can not see, to the same place with copy($****,'images/xpto.jpg') then...well I see the image ... but an image from the database, from the tmp file ... always gives empty square with red cross... Appreciate your help. Thanks JCG <!--teste.php--> <?php ini_set('upload_tmp_dir','/var/www/html/images/'); chmod('/var/www/html/images/', 0777); $con = mysql_connect('********','*****','******') or die('Erro a ligar SQL!!!'); /* Remote server Apache and MySQL ---- works fine, no errors! */ $db = mysql_select_db('*****') or die('Erro a ligar DB!!!'); /* works fine, no errors! */ $sql = "SELECT foto,id FROM fotos"; /* works fine, no errors! */ $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); /* works fine, no errors! */ ?> <table border="1"><tr><td>id</td><td>image</td></tr> <?php while($row=mysql_fetch_assoc($result)){ print '<tr><td>'.$row['id'].'</td><td>'; print '<img src="show.php?id='.$row['id'].'" height="75" width="100">'; } echo '</td></tr></table>' ?> <!--show.php--> <?php ini_set('upload_tmp_dir','/var/www/html/images/'); chmod('/var/www/html/images/', 0777); $con = mysql_connect('********','*****','******') or die('Erro a ligar SQL!!!'); /* Remote server Apache and MySQL ---- works fine, no errors! */ $db = mysql_select_db('*****') or die('Erro a ligar DB!!!'); /* works fine, no errors! */ ob_start(); $query = mysql_query("SELECT foto FROM fotos WHERE id={$_GET['id']}"); $row = mysql_fetch_array($query); $content = $row['foto']; header('Content-type: image/jpg'); echo $content; ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/ Share on other sites More sharing options...
Jamdog Posted May 23, 2012 Share Posted May 23, 2012 You are echoing the contents of your database, not an image... I assume that 'foto' in your database is the filename of the image, not the actual image data...? Instead of 'echo', try readfile: $content = $row['foto']; header('Content-type: image/jpg'); readfile($content); Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/#findComment-1347976 Share on other sites More sharing options...
jcg Posted May 23, 2012 Author Share Posted May 23, 2012 thanks for the reply! And I've tried readfile($content); ...but not worked No, 'foto' in my database is image data, is a field LONGBLOB. Appreciate your help. Thanks JCG Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/#findComment-1348013 Share on other sites More sharing options...
mrMarcus Posted May 23, 2012 Share Posted May 23, 2012 thanks for the reply! And I've tried readfile($content); ...but not worked No, 'foto' in my database is image data, is a field LONGBLOB. Appreciate your help. Thanks JCG Do you have the option to revert from using that column type? You don't want to store images within the database, but instead, simply store the name of the file in the table and have the file located in a folder/directory somewhere on the server. That way, you won't even need to reference a separate show.php file to display the images, either. You will be able to have them display right within teste.php Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/#findComment-1348018 Share on other sites More sharing options...
jcg Posted May 23, 2012 Author Share Posted May 23, 2012 it's true ... but I want to save the images in database...associated with a register...so I don't worry about the name nor location... Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/#findComment-1348027 Share on other sites More sharing options...
Jessica Posted May 23, 2012 Share Posted May 23, 2012 Images are files, and should be stored within the filesystem. Link to comment https://forums.phpfreaks.com/topic/262982-always-gives-empty-square-with-red-cross/#findComment-1348030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.