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 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题