H
H
HAbRAhabp2015-11-04 22:04:12
PHP
HAbRAhabp, 2015-11-04 22:04:12

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("Файл не существует");
            }
        }
    }

The directory /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 XB4ni.png, 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 aliasoutput this folder, everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-11-05
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question