R
R
Ruslan Absalyamov2019-10-16 11:26:42
JavaScript
Ruslan Absalyamov, 2019-10-16 11:26:42

How to make the code on the server work after entering the header ()?

I have a problem such that on my local code the code passes normally header("Content-Type: $FileMime");
And after it the file is deleted as it should, but on the server it happens that when it comes to this header, the code simply stops processing.
My code

/**
     * @param string $path
     * @param string $filename
     * @param string $contentDisposition
     * @return bool
     * @throws Exception
     * @throws \Exception
     */
    public static function DownloadDocument($path, $filename = 'documents', $contentDisposition = 'inline')
    {
        if (!file_exists($path)) {
            throw new \Exception('File ' . $path . ' not found');
        }
        $FileMime = mime_content_type($path);

        // сбрасываем буфер вывода PHP, чтобы избежать переполнения памяти выделенной под скрипт
        if (ob_get_level()) {
            ob_end_clean();
        }
        header("Content-Description: File Transfer");
        header("Content-Type: $FileMime");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".filesize($path));
        header("Content-Disposition: $contentDisposition; filename=$filename." . self::GetExtension($path));
        header("Expires: 0");
        header("Cache-Control: must-revalidate");
        header("Pragma: public");
        readfile($path);
        return true;
    }

    /**
     * @param int $id
     * @return bool
     * @throws Exception
     */
    public static function DocumentStatisticsUtm($id)
    {
        $fileName = $id . '.xlsx';
        $path = Yii::getAlias('@uploads') . '/temp/' . $fileName;
        if (file_exists($path)) {
            self::DownloadDocument($path);
            unlink($path);
            return true;
        }
        return false;
    }

So I did not understand why on different machines I have a different action. On the local is php7.1, and on the server 7.3. This is a test server, so there is such a discrepancy in the versions of php. Just if it matters to the given problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2018-07-26
@Casufi

https://developer.mozilla.org/en-US/docs/Web/API/E...
In its purest form, is returns the position of the block in the viewport. When opening, you take the position of the base block and calculate where to open the child block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question