[英]I am trying to download file through my application but am getting this error
[英]I am trying to download a file from mysql, I saved the file location in the database, now I am trying to make a download link for the user on my page
無法創建下載鏈接。 我正在從數據庫中獲取保存的路徑,然后嘗試建立一個鏈接以供下載,但是什么也沒有發生。 下面是我的代碼:
$query_print="SELECT vitae_pi FROM pi WHERE username='t124'";
$query_print_run=mysqli_query($conn,$query_print);
$query_print_recordset=mysqli_fetch_assoc($query_print_run);
$query_print_path=$query_print_recordset['vitae_pi'];
echo ' this is file path '.$query_print_path;
在這里,我只是嘗試為用戶t124創建下載鏈接,而不是使用當前用戶進行測試? 這是超鏈接代碼:
<?php echo "<a href='".$query_print_path."'>".DOWNLOAD."</a>"; ?>
有什么建議么?
這是我的移動文件功能:
protected function moveFile($file)
{
$filename = isset($this->newName) ? $this->newName : $file['name'];
//echo $filename;
$success = move_uploaded_file($file['tmp_name'], $this->destination . $filename);
if ($success) {
$result = $file['name'] . ' was uploaded successfully';
if (!is_null($this->newName)) {
$_SESSION['current_filename']=$this->newName;
echo $_SESSION['current_filename'];
$result .= ', and was renamed ' . $this->newName;
}
else{
$_SESSION['current_filename']=$file['name'];
echo $_SESSION['current_filename'];
}
//$result .= '.';
//echo $this->newName;
$this->messages[] = $result;
} else {
$this->messages[] = 'Could not upload ' . $file['name'];
}
}
使用文件路徑更新表:
$file_path_variable1= $destination1.$_SESSION['current_filename'];
echo '$file_path_variable1 : '.$file_path_variable1;
$query1="UPDATE proposal SET whitepaper_prop='$file_path_variable1' WHERE userName_prop='$currentuser'";
$result_query1=mysqli_query($conn,$query1);
....................解決方案代碼為:解決方案代碼為:
$query_print="SELECT vitae_pi FROM pi WHERE username='t115'";
$query_print_run=mysqli_query($conn,$query_print);
$query_print_recordset=mysqli_fetch_assoc($query_print_run);
$query_print_path=$query_print_recordset['vitae_pi'];
$dir= 'uploaded/';
$path=opendir($dir);
<?php
}while($query_pi_array=mysqli_fetch_assoc($query_pi_result));?>
<div>
<?php while($file=readdir($path)){
if($file != "." || $file !=".."){
if($file==$query_print_path){ ?>
<a href="<?php echo $dir.$query_print_path; ?>">Proposal Whitepaper</a>
這顯示什么?
<?php echo "<a href='".$query_print_path."'>".DOWNLOAD."</a>"; ?>
DOWNLOAD應該是PHP字符串的一部分,如果不是,它將被視為一個常量:
<?php echo "<a href='".$query_print_path."'>DOWNLOAD</a>"; ?>
另外,對HTML屬性使用雙引號:
<?php echo "<a href=\"$query_print_path\">DOWNLOAD</a>"; ?>
和優化的方式(避免無用的字符串解析):
<?php echo '<a href="'.$query_print_path.'">DOWNLOAD</a>'; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.