douqin3245 2015-10-28 03:19
浏览 137
已采纳

通过ftp服务器下载时无法重定向到正确的路径

Here i have a problem with the download.php. I am trying to download file but its not redirecting to the right path where i shared a folder on the ftp server. Its always redirecting to the address where all my file.php exist.

Here is my home download.php

<?php
include 'dbconfig';
include 'ftpconfig.php';
include 'aes.php';

session_start();
    if($_SESSION['user'] and ($_SESSION['nik'])){
    }
    else{ 
       header("location:index.php");
    }

$file = $_GET['id'];
$fileFtp = 'ftp://'.$ftp_user_name.':'.$ftp_user_pass.'@'.$ftp_server.'/'.$file;
$crypt = new aes_encryption();
$fileName = str_replace('.enc','',$fileFtp.$file);
$fileNamee = str_replace('.enc','',$file);

$dekrip = $crypt->decrypt_file($fileFtp.$file, $fileName);
if (!$dekrip) {
echo "Gagal";
}
else {
        echo '<script> window.location.href = '.$fileName,'; </script>';
echo "The file ".$fileNamee." downloaded sucessfully";
} 
?>

This is the code on my home.php to download

<td> <a href="download.php=<?php echo $row['file'] ?>" target="_blank">Download</a></td>

When i click the download, its redirect to where the all file.php exist

http://localhost/aes/download.php81208-mklh.pdf.enc

not in the shared folder on ftp server where i set in F:\ftp. and all the files is in that folder.

How can i fix that?

  • 写回答

2条回答 默认 最新

  • dongqia3502 2015-10-28 03:23
    关注

    You're missing ?id in your link before the = sign:

    <a href="download.php?id=<?php echo $row['file'] ?>"...
    

    Plus, seeing http://localhost/aes/download.php

    change it to:

    <a href="/aes/download.php?id=<?php echo $row['file'] ?>"...
    

    or

    <a href="http://localhost/aes/download.php?id=<?php echo $row['file'] ?>"...
    

    depending on the file's (download.php) location on your server.

    Error reporting should be set to catch and display notices.

    Make sure the path is correct and that your database query is correct with no errors, because $row['file'] suggests it.

    N.B.: (edit)

    Both your FTP and DB code need to be inside the same file. You're probably losing a connection somewhere by having your code in separate files.

    References:

    and use var_dump(); and print_r(); and your HTML source as debugging tools.

    Also make sure that your database's query in a while loop, doesn't end prematurely. Seeing another question of yours, you are using mysql_.

    I.e.: (notice the semi-colon at the end)

    while ($row = mysql_fetch_array($result)); // <<< that terminates it.
    {
        $file = $row["file"];
    }
    

    I have seen this happen before, it's an insight.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型