Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP下载文件已损坏(从ftp服务器下载时)_Php_Upload - Fatal编程技术网

PHP下载文件已损坏(从ftp服务器下载时)

PHP下载文件已损坏(从ftp服务器下载时),php,upload,Php,Upload,我在从特定文件夹下载文件(php)时遇到问题 当我下载并打开文件时,它会显示您的文件已损坏 当我检查上传文件和下载文件的大小时,它是相同的,但对于zip文件大小,它是不同的 没有打开任何文件 谁能说我错在哪里 if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) { $filename = $_GET['file']; } else { $filename = NULL; } $er

我在从特定文件夹下载文件(php)时遇到问题

当我下载并打开文件时,它会显示您的文件已损坏

当我检查上传文件和下载文件的大小时,它是相同的,但对于zip文件大小,它是不同的

没有打开任何文件

谁能说我错在哪里

if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
  $filename = $_GET['file'];
} 
else
{
  $filename = NULL;
}

$err = 'Sorry, the file you are requesting is unavailable.';
if (!$filename) {
// if variable $filename is NULL or false display the message
  echo $err;
} 
else 
{
// define the path to your download folder plus assign the file name
  $path = '/public_html/wp-content/uploads/'.$filename;
// check that file exists and is readable
  if (file_exists($path) && is_readable($path)) {
// get the file size and send the http headers
    $size = filesize($path);
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.$size);
    header('Content-Disposition: attachment;filename="'.basename($filename).'"');
    header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
// display the error messages if the file can´t be opened
    $file = @ fopen($path, 'rb');
    if ($file) {
// stream the file and exit the script when complete
      fpassthru($file);
      exit;
    } else {
      echo $err;
    }
  } else {
    echo $err;
  }

  exit;

}
在表中插入:

 echo "<tr><td><a href='?file=" . $row["FileupName"]. "'>".$row["FileupName"]."</td></tr>";

@Bekri它没有被下载…请告诉我代码的确切位置…我的代码(上面)的哪部分应该被替换没有Bekri它没有下载,但在url中我得到了文件名。虽然这可能回答了OP的问题,但发布没有任何解释的可靠代码块并没有任何教育目的。请解释为什么此代码是一个解决方案,或者它是否基于OP的更改内容和原因,以改进您的答案。@Bekir相同的问题损坏了您的文件编码utf-8
ob_clean();
flush();
readfile($file);
if (file_exists($path)) {

                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename=' . basename($path));
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header('Pragma: public');
                header('Content-Length: ' . filesize($path));
                ob_clean();
                flush();
                readfile($path);
                exit;
            }