Answer the question
In order to leave comments, you need to log in
Why doesn't readfile() work?
There is this code:
<?php
$id = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if($id != 'show') {
require "../../../db.php";
$db = new mysqli(db_host, db_user, db_pass, db_name);
if($array_ban = $db->query("SELECT * FROM `adverts` WHERE `id` = '$id'")->fetch_array()) {
// var_dump($array_ban);
$file = $array_ban['src'];
$mime = $array_ban['mime_type'];
$path = "/var/banners/{$file}";
if(file_exists($path)) {
header("Content-Type: " . $mime);
readfile($path);
}
else {
die("Файл не существует");
}
}
}
/var/banners/
certainly exists, as well as the files in it. The rights on the folder are 777. Task: using this php file to pull out the picture. But for some reason I get the icon of the picture , that is, there is no picture itself. Checked every variable. I came to the conclusion that for some other reason it does not work readfile().
. I have nginx + php-fpm. If you alias
output this folder, everything works fine.
Answer the question
In order to leave comments, you need to log in
Are you sure the path is correct? Open the browser console and check what exactly is returned from the server.
Something like this i.imgur.com/QBRFsmo.png
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question