DB画像をディレクトリへファイル出力完了

vi imgdb.php
<?
require_once("mysql.inc");
mysql_s("sns");
$sql="select bin,filename from c_image";
$r=mysql_query($sql);
while($row=mysql_fetch_array($r)){

$fp = fopen("$row[filename]", 'w');
$row[bin]=base64_decode($row[bin]);
fwrite($fp, $row[bin]);
fclose($fp);
}
?>
:wq!

php imgdb.php