Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从数据库中用php显示图像_Php - Fatal编程技术网

从数据库中用php显示图像

从数据库中用php显示图像,php,Php,大家好,我正试图用php从我的数据库中显示一幅图像,我将图像的名称输入到我的数据库中,而不是扩展名,我现在想检索这个名称并将其扩展名放在一起,然后将其显示在表单上,但我遇到了一些困难,它根本无法工作,有人能帮忙吗 $id = null; $Cover= null; if ( !empty($_GET['id'])) { $id = $_REQUEST['id']; } if ( null==$id ) { header("Location: index.php"); } els

大家好,我正试图用php从我的数据库中显示一幅图像,我将图像的名称输入到我的数据库中,而不是扩展名,我现在想检索这个名称并将其扩展名放在一起,然后将其显示在表单上,但我遇到了一些困难,它根本无法工作,有人能帮忙吗

$id = null;
$Cover= null;
if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
}
 if ( null==$id ) {
    header("Location: index.php");
} else {
     $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
     $q = mysqli_query($dbc,"SELECT * FROM movie WHERE MovieID = '$id' ");
   while($r=mysqli_fetch_array($q))
{   
    $title = $r["Title"];
    $tag = $r["Tag"];
    $Year = $r["YEAR"];
     $Cast = $r["Cast"];
    $Cover = $r["Cover"];

}
下面是提取的代码

      $name = FALSE; // Flag variable:

      // Check for an image name in the URL:
     if (isset($_GET['image'])) {

// Make sure it has an image's extension:
$ext = strtolower ( substr ($_GET['image'], -4));

if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {

    // Full image path:
    $image = "uploads/{$_GET['image']}";

    // Check that the image exists and is a file:
    if (file_exists ($image) && (is_file($image))) {

        // Set the name as this image:
        $name = $_GET['image']; 

    } // End of file_exists() IF.

 } // End of $ext IF.

        } // End of isset($_GET['image']) IF.

   // If there was a problem, use the default image:

  // Get the image information:
    $info = getimagesize($image);
    $fs = filesize($image);

   // Send the content information:
    header ("Content-Type: {$info['mime']}\n");
    header ("Content-Disposition: inline; filename=\"$name\"\n");
     header ("Content-Length: $fs\n");

   // Send the file:
      readfile ($image);
          }
                ?> 

$image未按您的评论所述定义

$ext = strtolower(substr($_GET['image'], -4));

var_dump($ext, $_GET['image']);

if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {

    // Full image path:
    $image = "uploads/{$_GET['image']}";

    // Check that the image exists and is a file:
    if (file_exists($image) && (is_file($image))) {

        // Set the name as this image:
        $name = $_GET['image'];

        $info = getimagesize($image);
        $fs = filesize($image);

        // Send the content information:
        header("Content-Type: {$info['mime']}\n");
        header("Content-Disposition: inline; filename=\"$name\"\n");
        header("Content-Length: $fs\n");

        // Send the file:
        readfile($image);
    } // End of file_exists() IF.
}

它不工作不是错误:)发生了什么事?@paistra Errore如下注意:未定义变量:C:\xampp\htdocs\star\u crud\read.php中的图像,在第128行警告:getimagesize():第128行C:\xampp\htdocs\star\u crud\read.php中的文件名不能为空注意:未定义变量:第129行C:\xampp\htdocs\star\u crud\read.php中的图像注意:未定义变量:第137行C:\xampp\htdocs\star\u crud\read.php中的图像警告:readfile():C:\xampp\htdocs\star\u crud\read.php第137ok行中的文件名不能为空,这样您就不用输入“if”指令了。@paistra您这么说是什么意思?$image没有按您的注释定义。所以你可以访问一个空文件。尝试在$ext之后使用var dump$\u GET['image']。