【发布时间】:2018-09-07 13:29:58
【问题描述】:
我一直有 - 我认为权限问题 - 解压缩文件(这部分没问题)并将内容移动到写入文件夹。
我正在运行简单的代码:
$zip = new ZipArchive( );
$x = $zip->open( $file );
if ( $x === true ) {
$zip->extractTo( $target );
$zip->close( );
unlink( $file );
rmove( __DIR__ . '/' . $target . '/dist', __DIR__ );
} else {
die( "There was a problem. Please try again!" );
}
其中rmove() 是一个简单的递归函数,它遍历内容并将rename() 应用于每个文件。
问题是解压缩顺利,文件被复制,但没有移动 - 从临时文件夹中删除。到目前为止,我读到这可能是由于在重命名时没有对解压缩文件的写权限。
解压时如何控制这些权限?
更新:rmove() 的内容:
function rmove( $src, $dest ) {
// If source is not a directory stop processing
if ( ! is_dir( $src ) ) return false;
// If the destination directory does not exist create it
if ( ! is_dir( $dest ) ) {
if ( ! mkdir( $dest ) ) {
// If the destination directory could not be created stop processing
return false;
}
}
// Open the source directory to read in files
$i = new DirectoryIterator( $src );
foreach( $i as $f ) {
if ( $f->isFile( ) ) {
echo $f->getRealPath( ) . '<br/>';
rename( $f->getRealPath( ), "$dest/" . $f->getFilename( ) );
} else if ( ! $f->isDot( ) && $f->isDir( ) ) {
rmove( $f->getRealPath( ), "$dest/$f" );
unlink( $f->getRealPath( ) );
}
}
unlink( $src );
}
【问题讨论】:
-
您是否收到任何错误消息
-
否 - 根本没有错误消息 -
-
请添加
rmove()的内容...
标签: php permissions ziparchive