L
L
Lankaa2017-11-20 00:02:03
JavaScript
Lankaa, 2017-11-20 00:02:03

How to implement downloading files from the server to the client?

The downloads are located outside the project folder. I can't figure out how to get the file in this case.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ipokos, 2017-11-20
@ipokos

If they are within the server, you can go up to the directory above ( ../ )
There must be read permissions from this directory
ps which is fundamentally wrong.
If on another server, then as "absolute links" have already written

E
Exploding, 2017-11-20
@Exploding

Probably it's not about the paths, but about downloading?
Here it may be:

function downloadFile($file, $fileName, $ctype) {
        if (file_exists($file)) {
            if(ob_get_level()!==0) ob_clean();
            header('Content-Description: File Transfer');
            header('Content-Type: '.$ctype.'');
            header('Content-Length: ' . filesize($file));
            header('Content-Disposition: attachment; filename=' . $fileName);
            readfile($file);
            unlink($file);
            exit;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question