Lewis Smith
Lewis Smith

Reputation: 1345

file_put_contents failed to open stream even though folder is there

This is really simple and yet I am really struggling.

So I am downloading a file from a url and trying to save it into a folder like this:

file_put_contents('../uploads/' . $newFilename, fopen('http:' . $process->output->url, 'r'));

When I run that I get this error: message: "file_put_contents(../uploads/20181028203041.mp3): failed to open stream: No such file or directory"

When I run this line:

file_put_contents($newFilename, fopen('http:' . $process->output->url, 'r'));

The file drops nicely into my public folder. I do have an uploads folder, but this just isn't working. What silly mistake have I made here.

Proof of the folder: enter image description here

Please help!

Upvotes: 1

Views: 1103

Answers (1)

Artyom Blagoda
Artyom Blagoda

Reputation: 368

If you can successfully save to public in this way, than try to change '../uploads/' to uploads/. In case of ../uploads/ you are trying to save to beatpub/uploads folder.

Upvotes: 3

Related Questions