Jump to content

always gives empty square with red cross!!!! :'(


jcg

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.