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


store new filename in mysql database verot class.upload.php

所以我使用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");

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

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

简单:

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");