在变量中检索文件名


Retrieve filename in a variable

将文件从一个文件夹移动到另一个文件夹,我使用以下代码:

$new_file = new File($file['destination']->getPath() . File::SEPARATOR . $file['file']->getName());

现在,我需要添加一个唯一的ID,并在数据库中存储一个文件名。OK for uniid ():

$new_file = new File($file['destination']->getPath() . File::SEPARATOR . uniqid() . '---' . $file['file']->getName());

的结果是这样的文件名:514685 b08e6db——sl004321_7_03 - 2013. - pdf

现在,如何在变量中检索文件名以存储在MySQL上?

您可以将其存储在一个变量中并使用,如

$filename = uniqid() . '---' . $file['file']->getName(); //your filename
$new_file = new File($file['destination']->getPath() . File::SEPARATOR . $filename);