Welcome Guest, Not a member yet? Register   Sign In
Download of a file with file_get_contents - doesn't work
#1

[eluser]mci[/eluser]
Hi

I'm trying to write a function to download a file but I always get the error:

"A PHP Error was encountered

Severity: Warning

Message: file_get_contents(user_data/data.zip) [function.file-get-contents]: failed to open stream: No such file or directory

Filename: controllers/data.php

Line Number: 48
"

The "user_data" folder is in the root directory and upload is working.

Code:
function download($name)
    {
        $path_to_document = 'user_data/'.$name;
        $data = file_get_contents($path_to_document);
        $file_name = split('/', $path_to_document);
        $size = sizeof($file_name);
        $name = 'dl_' . url_title($name[$size - 1]);
        force_download($name, $data);
    }
#2

[eluser]WanWizard[/eluser]
You're using a relative path, so it's not trying to read from a folder in the root, it's trying to read from a folder in the controllers directory.
#3

[eluser]mci[/eluser]
Ok, thank you for the quick answer.




Theme © iAndrew 2016 - Forum software by © MyBB