gpt4 book ai didi

php - 我正在尝试从 mysql 下载文件,我将文件位置保存在数据库中,现在我正在尝试为我的页面上的用户创建下载链接

转载 作者:行者123 更新时间:2023-11-29 12:52:40 25 4
gpt4 key购买 nike

无法创建下载链接。我正在获取从数据库保存的路径,然后尝试创建一个链接供其下载,但没有任何反应。下面是我的代码:

$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>'; ?>

关于php - 我正在尝试从 mysql 下载文件,我将文件位置保存在数据库中,现在我正在尝试为我的页面上的用户创建下载链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com