无法创建下载链接。我正在获取从数据库保存的路径,然后尝试建立一个链接供它下载,但没有任何反应。 以下是我的代码:
$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>
答案 0 :(得分:1)
这显示了什么?
<?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>'; ?>