php move file 路径,php - move_uploaded_file()期望参数2是有效路径,给定对象 - 堆栈内存溢出...

我正在使用Symfony 2.3保存由表单POST上传的文件。

这是我在控制器中使用的代码:

$fileDir = '/home2/divine/Symfony/src/App/Bundle/Resources/public/files';

$form['my_file']->getData()->move($fileDir, 'book.pdf');

在水下,Symfony执行此代码来移动文件:

move_uploaded_file("/tmp/phpBM9kw8", "/home2/divine/Symfony/src/App/Bundle/Resources/public/files/book.pdf");

公共目录具有777权限。

这是我得到的错误:

"Could not move the file "/tmp/phpBM9kw8" to "/home2/divine/Symfony/src/App/Bundle/Resources/public/files/book.pdf"

(move_uploaded_file() expects parameter 2 to be valid path, object given)"

我正在使用PHP 5.3。

更新:

这是执行move_uploaded_file()的代码剪切:

// Class: Symfony\Component\HttpFoundation\File\UploadedFile

$target = $this->getTargetFile($directory, $name);

if (!@move_uploaded_file($this->getPathname(), $target)) {

// etc...

$ target“变量在这里创建:

protected function getTargetFile($directory, $name = null) {

// Some error handling here...

$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));

return new File($target, false);

}

$ target变量就是File类。 它有一个__toString()方法,继承自SplFileInfo:

/**

* Returns the path to the file as a string

* @link http://php.net/manual/en/splfileinfo.tostring.php

* @return string the path to the file.

* @since 5.1.2

*/

public function __toString () {}

但不知何故__toString方法无法正常工作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值