dtl85148 2016-05-02 12:01
浏览 46
已采纳

PHP动作表单嵌入HTML

My form action page is PHP but I want to echo a clickable link and I think PHP doesn´t support this. I've embed this PHP code in HTML tags but it echos the tags in the page.

Code:

<?php
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");

include 'connect.php';

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);


// Allow certain file formats
if($imageFileType != "sql") {
    echo "Sorry, only SQL files are allowed.
";
    $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.
";
        $sqlfile = fopen($target_file, "r") or die("Unable to open file!");
        $contents = file($target_file);
        foreach($contents as $line) {
            $result = mysql_query($line) or die('Query failed: ' . mysql_error());
            $file_name= str_replace("'", "", basename($target_file,".sql"));


        }


        echo "The new data was inserted in database.
";
        echo "View your data in http://localhost/public_html/PAD/index.php?user=$file_name";
        fclose($sqlfile);

    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}


?>

The problem is here:

echo "View your data in http://localhost/public_html/PAD/index.php?user=$file_name";

How can I make this link clickable?

Thanks!

  • 写回答

3条回答 默认 最新

  • dsxon40042 2016-05-02 12:36
    关注

    Your Question seems to have answered itself. All you have to do is just wrap the link in an Anchor Tag like so

    <?php
        header('content-type: application/json; charset=utf-8');
        header("access-control-allow-origin: *");
    
        include 'connect.php';
    
        $target_dir    = "uploads/";
        $target_file   = $target_dir . basename($_FILES["fileToUpload"]["name"]);
        $uploadOk      = 1;
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    
    
        // Allow certain file formats
        if($imageFileType != "sql") {
            echo "Sorry, only SQL files are allowed.
    ";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Your file was not uploaded.";
           // if everything is ok, try to upload file
        } else {
       if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.
    ";
            $sqlfile = fopen($target_file, "r") or die("Unable to open file!");
            $contents = file($target_file);
        foreach($contents as $line) {
            $result = mysql_query($line) or die('Query failed: ' . mysql_error());
            $file_name= str_replace("'", "", basename($target_file,".sql"));
        }
    
    
        echo "The new data was inserted in database.
    ";
        //THIS IS THE ONLY PLACE YOU NEED TO ADDRESS: WRAP URL IN <A> TAGS:
        echo "<a href='http://localhost/public_html/PAD/index.php?user={$file_name}' class='view-data-link'>View your data</a>";
        fclose($sqlfile);
    
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题