使用 vfsStream 测试 move_uploaded_file 和 is_uploaded_file
我尝试使用 PHPUnit 和 vfsStream 测试 move_uploaded_file 和 is_uploaded_file 。它们总是返回 false。
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 (或任何数据)吗? 谢谢。
I've tried to test move_uploaded_file and is_uploaded_file with PHPUnit and vfsStream. They always return false.
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'));
}
Is it possible? How do I do that?
Can I post a vfsStreamFile (or any data) without a form, just using PHP code?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会。
move_uploaded_file
和is_uploaded_file
是专门为处理上传的文件而设计的。它们包括额外的安全检查,以确保文件在上传完成和控制脚本访问文件之间的时间内没有被篡改。注意:从脚本内更改文件被视为篡改。
No.
move_uploaded_file
andis_uploaded_file
are specifically designed to handle uploaded files. They include extra security checks to ensure that the file's not been tampered with in the time between the upload completing and the controlling script accessing the file.Note: changing the file from within the script counts as tampering.
假设您正在使用类,您可以创建一个父类。
Assuming you're using classes you can create a parent class.