Php 类ZipArchive(),函数出现一些错误
我在我的代码中查找错误已经两天了:Php 类ZipArchive(),函数出现一些错误,php,Php,我在我的代码中查找错误已经两天了: <?php echo $_FILES['import']['name']; ?> <br/> <?php echo $_FILES['import']['type']; ?> <br/> <?php echo $_FILES['import']['size']; ?> <br/> <?php echo $_FILES['import']['tmp_name']; ?> <
<?php
echo $_FILES['import']['name']; ?> <br/> <?php
echo $_FILES['import']['type']; ?> <br/> <?php
echo $_FILES['import']['size']; ?> <br/> <?php
echo $_FILES['import']['tmp_name']; ?> <br/> <?php
echo $_FILES['import']['error'];
if ($_FILES['import']['error'] > 0) {
echo "Erreur lors du transfert";
}
else {
echo "Transfert Ok" ;?> <br/> <?php
$nom = $_FILES['import']['name'];
$localisation = $_FILES['import']['tmp_name'];
echo $nom; ?> <br/> <?php
echo $localisation; ?> <br/> <?php
$zip = new ZipArchive();
$res = $zip->open($localisation."/".$nom);
// echo $res;
if($res === TRUE) {
echo 'ok';
}
else {
echo 'erreur';
}
}
?>
我的问题在于ZipArchive
类。对我来说,open()
和extractTo()
函数不起作用
始终编辑此代码以找到解决方案。现在我试图“打开”,但它不起作用。我不知道为什么。对我来说,路径是不正确的,但当我看到路径时(使用
echo$localization.“/”$nom
),它实际上是正确的
有没有人对新手有什么解决方案或建议 函数不起作用的原因可能是行
$res=$zip->open($localization.“/”$nom)代码>-这将导致出现一个字符串,如/tmp/a23mt.tmp/somefile.zip
,这将是错误的。尽管您可能希望指定一个特定的文件夹路径来保存上传的文件,而不是脚本的当前工作目录,但以下内容可能会有所帮助
/* for convenience, create an object representation of the uploaded file */
$file=(object)$_FILES['import'];
/* assign variables */
$name=$file->name;
$type=$file->type;
$size=$file->size;
$tmp=$file->tmp_name;
$error=$file->error;
if( $error==UPLOAD_ERR_OK ){
if( is_uploaded_file( $tmp ) ){
/* need to store the file somewhere */
$target = __DIR__ . DIRECTORY_SEPARATOR . $name;
/* move the uploaded file before processing */
$result = move_uploaded_file( $tmp, $target );
/* was the file moved successfully? */
if( file_exists( $target ) ){
clearstatcache();
/* do stuff - zip */
$zip = new ZipArchive();
$result = $zip->open( $target );
echo $result ? 'ok' : 'erreur';
} else {
echo "Error moving/saving file!";
}
} else {
echo "Error! Not an uploaded file...attempted hack!"
}
} else {
echo "Erreur lors du transfert!"
}
是否有可以添加到问题中的错误日志?这将有助于其他人给出一个解决方案。我现在没有错误,只是这段代码没有“输入”if条件。(如果($res==TRUE){echo'ok';})。我正在这篇博文下尝试这个解决方案谢谢这个解决方案,它很有效!现在,我正试图提取我的文件,非常感谢。