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(); ?> Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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.