Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

more image probs

Status
Not open for further replies.

bastienk

Programmer
Joined
Mar 3, 2004
Messages
326
Location
CA
Trying to get an image out the db and into a file...is not saving/writing to the file...file is being created but not passed to the file...getting a Undefined variable: img in the page where $img is the db query result...




Code:
$results = mysql_query($sql) or die ("Can't connect to DB because ".mysql_error()); 
//check for results 
if (($results)&&(mysql_num_rows($results)==1)){ 
   
  //we have the image 
  while ($row=mysql_fetch_array($results)){ 
    $img = $row['evidence']; 
  }//end while 

}//end if 

//save the photo temporarily to the disk - delete when finished 
$temp_image = fopen($my_image,"w+b"); 
fwrite ($temp_image, $img); 
fclose($temp_image);



Bastien

Cat, the other other white meat
 
There are a few things:
1. Your construct doesn't take into consideration that there is no result from the query. An empty file is written.

2. Is there only 1 image at a time? Your SQL doesn't show. If so, no need for the while loop.

3. This way of doing images is complicated and awkward. Instead of having it in the filesystem to begin with (no mess with header directives etc.) you put it into a table, then get it out again to write it to a file....
 
there is a result from the query, there is only one pic at a time.

Yes, its awkward but a fix to an ASP system that I was tasked to do...no, its not my ideal way of doing it, but until the system gets fully converted to PHP, I gotta live with it


Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top