【发布时间】:2018-06-26 01:41:07
【问题描述】:
我有这段代码应该创建一个随机目录并将上传内容移到那里:
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . mkdir( 'assets/post/email_uploads/{uniqid(attachment_)}', 0777 ) . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
路径assets/post/email_uploads/ 已经存在,所以随机文件夹应该进入email_uploads。我面临的问题是在DIRECTORY_SEPARATORs 之间放置什么并让一切正常。
当我尝试mkdir( 'assets/post/email_uploads/{uniqid(attachment_)}', 0777 ) 或
mkdir( 'assets/post/email_uploads/'.uniqid(attachment_), 0777 ) - 未创建文件夹,上传放在根目录。
当我尝试时
$attchmentPath = 'assets/post/email_uploads/';
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $attchmentPath.mkdir( uniqid(attachment_), 0777 ) . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
或
$attchmentPath = 'assets/post/email_uploads/';
$randomDir = mkdir( uniqid(attachment_), 0777 );
$newPath = $attchmentPath.$randomDir;
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $newPath . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
文件夹是在根目录下创建的,而不是所需的路径,文件根本没有上传。
【问题讨论】:
-
echo 'assets/post/email_uploads/{uniqid(attachment_)}';- 现在这告诉你什么……? -
单引号还是双引号??函数调用需要在调用之前进行转义,如果要解析变量,则应该在双引号内 - 在单引号内,你看到的就是你得到的
-
@CBroe 当我回显它按原样输出时 -
assets/post/email_uploads/{uniqid(attachment_)}但是当我回显'assets/post/email_uploads/'.uniqid(attachment_)它输出所需的路径但仍然无法正常工作 -
@RamRaider 我刚刚用双引号尝试过 - 没有成功
标签: php random file-upload mkdir