• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

howto get image from db and store it in directory

I use this code to show image that stored in database :

$sql    = "SELECT * FROM picture WHERE username='$u'";
$result = mysql_query ($sql);
if (mysql_num_rows ($result)>0) {
  $row = @mysql_fetch_array ($result);
  $image_type = $row["image_type"];
  $image = $row["image"];
  Header ("Content-type: $image_type");
  print "$image";
}

my problem now, how to get the file and save it to directory?
0
hendri2
Asked:
hendri2
1 Solution
 
BlazCommented:
The easiest way is to click "save image" in the browser...

However you can write a php script for example (like the one you are writing now) and instead of writing to the client (print "$image") writing to a file:

$file = fopen("/home/user/images/img1.jpg","w");
fwrite($file, $image);

http://www.php.net/manual/en/function.fwrite.php
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now