0

我的 PHP 图片上传代码有一个小问题,我没有将正确的文件名保存到我的 MySQL 数据库中。

请告诉我我做错了什么。

PHP

// Upload File to Directory
$code = md5(time());
$image = $_FILES['userfile']['name'];
$imagename = $code.$image;
$uploaddir = '../_gallery/' . $imagename;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

MySQL查询

$sql="UPDATE b_events 
      SET ename = '$event_name', 
          edescription = '$event_description', 
          edate = '$event_date', 
          etime = '$event_time', 
          ecost = '$event_cost', 
          eimage = '$imagename' 
      WHERE id = '$update'";
$result=mysql_query($sql);
4

1 回答 1

1

您需要将此名称插入数据库,因为您使用此名称将文件上传到目录

或通过为新变量赋值

$sql="UPDATE b_events 
          SET ename = '$event_name', 
              edescription = '$event_description', 
              edate = '$event_date', 
              etime = '$event_time', 
              ecost = '$event_cost', 
              eimage = '$uploadfile' 
        WHERE id = '$update'";

或者

  $file_name =basename($_FILES['userfile']['name'];

$sql="UPDATE b_events 
          SET ename = '$event_name', 
              edescription = '$event_description', 
              edate = '$event_date', 
              etime = '$event_time', 
              ecost = '$event_cost', 
              eimage = '$file_name' 
        WHERE id = '$update'";
于 2012-07-20T10:52:53.007 回答