在mysql数据库verot class.upload.php中存储新文件名

时间:2014-04-23 00:53:02

标签: php mysql forms upload

所以我使用http://www.verot.net/php_class_upload_docs.htm?lang=en-GB将文件上传到mysql数据库。我是mysql的新手,所以请原谅我的无知。

以下代码段上传图片,正确重命名,但将旧文件名存储在数据库表中。

include('class.upload.php');

$t = time();
$foo = new Upload($_FILES['receipt_u']);
if ($foo->uploaded) {
$foo->file_new_name_body = "img_$t";
$foo->file_max_size = '4194304'; //4MB
$foo->Process('pics'); 
}

$receipt_img =($_FILES['receipt_u']['name']);

$sql = "INSERT INTO product (receipt_u) VALUES (:rcpt)";
$q = $conn->prepare($sql);
$q->execute(array(':rcpt'=>$receipt_img));
    header("location: ../index.php");

实际上有很多数据被传递到数据库中,但我为此目的将其删除,因为这是唯一给我带来麻烦的事情。

为什么将原始文件名发布到数据库而不是新文件名?

1 个答案:

答案 0 :(得分:1)

简单:

echo $foo->file_dst_name;

您的新代码如下:

$t = time();
$foo = new Upload($_FILES['receipt_u']);
if ($foo->uploaded) {
$foo->file_new_name_body = "img_$t";
$foo->file_max_size = '4194304'; //4MB
$foo->Process('pics'); 
}

//here its recipt image new 
$receipt_img = $foo->file_dst_name;

$sql = "INSERT INTO product (receipt_u) VALUES (:rcpt)";
$q = $conn->prepare($sql);
$q->execute(array(':rcpt'=>$receipt_img));
    header("location: ../index.php");