PDA

View Full Version : Help with image sending script


gigiloumill
08-20-2009, 06:23 PM
Guys, I have this script for sending images in db. The problem is that it's not posting into the db. Can someone please show me what I'm doing wrong. Thanks

<?php
$cn = mysql_connect("localhost","pass","pass");
mysql_select_db("db_image",$cn);

if ($act=='view'){
$sql="SELECT * FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('sorry');
$data=mysql_fetch_array($rst);
$type=$data[type];
Header("Content-type: $type");
echo $data[image];
}

if ($act=='del'){
$sql="DELETE FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('sorry');
}

if($submit)
{
$type = $_FILES['file']['type'];
copy ($_FILES['file']['tmp_name'], "tmp/tmp.jpg") or die ("Could not copy");
$filer="tmp/tmp.jpg";
$handle = fopen($filer, "r");
$pure = addslashes(fread($handle, filesize($filer)));
$sql = "insert into tbl_image(image,type) values('$pure','$type')";
$result = mysql_query($sql,$cn)or die(mysql_error());

}

$sql="SELECT * FROM tbl_image";
$rst=mysql_query($sql) or die('sorry');
while ($data=mysql_fetch_array($rst)){
$id=$data[id];
echo "picture no $id <a href='./image.php?act=del&id=$id'>delete</a><br><img src='./image.php?act=view&id=$id'><br><br>";
}

?>

gigiloumill
08-21-2009, 02:05 AM
Anyone?...

edbr
08-21-2009, 02:44 AM
did u test this part seperately ?

$type = $_FILES['file']['type'];
copy ($_FILES['file']['tmp_name'], "tmp/tmp.jpg") or die ("Could not copy");
$filer="tmp/tmp.jpg";
$handle = fopen($filer, "r");
$pure = addslashes(fread($handle, filesize($filer)));
$sql = "insert into tbl_image(image,type) values('$pure','$type')";
$result = mysql_query($sql,$cn)or die(mysql_error());