我尝试使用 PHPUnit 和 vfsStream 测试 move_uploaded_file 和 is_uploaded_file。他们总是返回错误。
public function testShouldUploadAZipFileAndMoveIt()
{
$_FILES = array('fieldName' => array(
'name' => 'file.zip',
'type' => 'application/zip',
'tmp_name' => 'vfs://root/file.zip',
'error' => 0,
'size' => 0,
));
vfsStream::setup();
$vfsStreamFile = vfsStream::newFile('file.zip');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamFile);
$vfsStreamDirectory = vfsStream::newDirectory('/destination');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamDirectory);
$fileUpload = new File_Upload();
$fileUpload->upload(
vfsStream::url('root/file.zip'),
vfsStream::url('root/destination/file.zip')
);
$this->assertFileExists(vfsStream::url('root/destination/file.zip'));
}
这可能吗?我怎么做? 我可以只使用 PHP 代码在没有表单的情况下发布 vfsStreamFile(或任何数据)吗? 谢谢。
最佳答案
没有。 move_uploaded_file
和 is_uploaded_file
专门用于处理上传的文件。它们包括额外的安全检查,以确保文件在上传完成和控制脚本访问文件之间的时间内未被篡改。
注意:从脚本中更改文件算作篡改。
关于php - 使用 vfsStream 测试 move_uploaded_file 和 is_uploaded_file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839855/