简体   繁体   English

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

[英]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.

相关问题 我正在尝试通过我的应用程序下载文件,但出现此错误 - I am trying to download file through my application but am getting this error 我正在尝试跳过“Google Drive 无法扫描此文件中的病毒”并直接生成下载链接 - I am trying to skip 'Google Drive can't scan this file for viruses' and directly generate the download link 我正在尝试将我的学生列表与个人资料页面链接 - i am trying to link my student list with there profile page 我正在尝试用php写文件并下载它。 始终第一行显示为空白,这是错误的 - I am trying write file with php and download it. Always first line appears in blank and that is wrong 我正在尝试生成.sql转储文件并使用php自动下载 - I am trying to to generate a .sql dump file and auto-download using php 我正在尝试在.php文件中创建到另一个.php文件的链接 - I am trying to create a link in a .php file to another .php file 我正在尝试将多个图像下载为 zip 文件,但使用 laravel 7 时出错 - I am trying to download multiple image as a zip file but getting error using laravel 7 我试图在HTML文件中通过PHP通过MYSQL显示图像。 我的代码有什么问题? - I am trying to display an image from MYSQL via PHP in an HTML file. What is wrong with my code? 我正在尝试做一个在数据库(MySQL)中注册用户的注册表 - I am trying to do a registration form that registers a user in a database (MySQL) 我正在尝试制作管理员和登录页面 - i am trying to make admin and login page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM