Jump to content

Help with image sending script


nysmenu

Recommended Posts

Guys, I have this scrip to send images into a db. the problem is that it won't post 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>";
            }

?> 

Link to comment
Share on other sites

if($submit)?? $submit isn't even defined. Use if (!empty($_POST))

 

This seems to be working and now I'm getting this:

 

Warning: copy(tmp/tmp.jpg) [function.copy]: failed to open stream: No such file or directory in C:\wamp\www\websites\test\image.php on line 22

Could not copy

 

This is not my script, therefore, I do not know what "(tmp/tmp.jpg)" this is.

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.