通过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?

这里我遇到了 download.php code>的问题。 我正在尝试下载文件,但它没有重定向到我在ftp服务器上共享文件夹的正确路径。 它总是重定向到我所有的 file.php code>存在的地址。 p>

这是我的家 download.php code> p>

 &lt;?php 
include'dbconfig'; 
include'ftpconfig.php'; 
include'aes.php'; 
 
session_start(); 
 if($ _ SESSION [  'user']和($ _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  - &gt; decrypt_file($ fileFtp。$ file,$ fileName); 
if(!$ dekrip){
echo“Gagal”; 
} 
else {
 echo'&lt; script&gt;  window.location.href ='。$ fileName,';  &lt; / script&gt;'; 
echo“文件”。$ fileNamee。“已成功下载”; 
} 
?&gt; 
  code>  pre> 
 
 

这是 我的 home.php code>上的代码下载 p>

&lt; td&gt; &lt; a href =“download.php =&lt;?php echo $ row ['file']?&gt;” target =“_ blank”&gt;下载&lt; / a&gt;&lt; / td&gt; code> p>

当我点击下载时,它会重定向到所有 file.php的位置 code>存在 p>

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

不在我在 F:\ ftp code>中设置的ftp服务器上的共享文件夹中 。 并且所有文件都在该文件夹中。 p>

我该如何解决? p> div>

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.

If you put a header before any HTML that is dumped to the client you will redirect using PHP (server side, so you can send headers):

header('Location: http://www.yoursite.com/file_location.php');

If you want to do a JavaScript redirect you will use something like (client side, so the page can start loading already):

<script type="text/javascript">
<!--
window.location = "http://www.yoursite.com/file_location.php"
//-->
</script>