[英]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
Unable to create the download link. 无法创建下载链接。 I am fetching the path saved from database and then try to make a link for it to download, but nothing happens. 我正在从数据库中获取保存的路径,然后尝试建立一个链接以供下载,但是什么也没有发生。 Below is my code: 下面是我的代码:
$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;
Here I am simply trying to create the download link for user t124, instead of using the current user for testing purposes? 在这里,我只是尝试为用户t124创建下载链接,而不是使用当前用户进行测试? This is hyperlink code: 这是超链接代码:
<?php echo "<a href='".$query_print_path."'>".DOWNLOAD."</a>"; ?>
Any suggestions? 有什么建议么?
This my move file function: 这是我的移动文件功能:
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'];
}
}
Updating the table with file path: 使用文件路径更新表:
$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);
.................... SOLUTION CODE IS: Solution code is : ....................解决方案代码为:解决方案代码为:
$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>
What does this display ? 这显示什么?
<?php echo "<a href='".$query_print_path."'>".DOWNLOAD."</a>"; ?>
DOWNLOAD should be part of the PHP string, if not, it will be considered as a constant : DOWNLOAD应该是PHP字符串的一部分,如果不是,它将被视为一个常量:
<?php echo "<a href='".$query_print_path."'>DOWNLOAD</a>"; ?>
Also, use double quotes for HTML attributes : 另外,对HTML属性使用双引号:
<?php echo "<a href=\"$query_print_path\">DOWNLOAD</a>"; ?>
And the optimized way (to avoid useless string parsing) : 和优化的方式(避免无用的字符串解析):
<?php echo '<a href="'.$query_print_path.'">DOWNLOAD</a>'; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.