这些代码总是提示无效的路径文件。我不知道为什么:/

时间:2013-12-10 02:39:35

标签: php download

<?php

if(isset($_POST['sportname'])){ 
    include("connect.php");
    $name = $_POST['sportname'];
    $sql = "Select docs From tbl_sport WHERE sprt_name= '".$name."'";
    $result = mysql_query($sql);
    $row=mysql_fetch_object($result);
    $file = $row->docs; 


    ini_set("allow-url-fopen", true);
    // Fetch the file info.
    $filePath = 'http://prisaa-region11.com/Docs/'.$file;

    if(file_exists($filePath)) {
        $fileName = basename($filePath);
        $fileSize = filesize($filePath);

        // Output headers.
        header("Cache-Control: private");
        header("Content-Type: application/stream");
        header("Content-Length: ".$fileSize);
        header("Content-Disposition: attachment; filename=".$fileDisplayName);

        // Output file.
        readfile ($filePath);                   
        exit();
    }
    else {
        die('The provided file path is not valid.');
    }
}       
?>

我不知道路径错误

1 个答案:

答案 0 :(得分:0)

您可能想尝试Filter Validator

if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
    die('Not a valid URL');
}

检查这个类似的线程 Best way to check if a URL is valid

相关问题