Umer Fayyaz
Umer Fayyaz

Reputation: 497

file_put_contents() store files outside the public folder laravel

Hi I am trying to save file inside public folder using this file_put_contents() but in local it working fine it save file in public folder but in live server it save outside the public folder.

file_put_contents($lesson->id.'test'.$i.'.mp3', $resp->getAudioContent());

enter image description here

my local URL contains public word but live URL is without public word Thanks for any help

Upvotes: 0

Views: 1603

Answers (1)

N69S
N69S

Reputation: 17216

You did not declare the root folder of your application the same as the server. To put your file in the public folder on the server do

file_put_contents('public/'.$lesson->id.'test'.$i.'.mp3', $resp->getAudioContent());

You can also use the absolute path of your public folder to make it work on both your local installation and the server

file_put_contents(public_path($lesson->id.'test'.$i.'.mp3'), $resp->getAudioContent());

Upvotes: 2

Related Questions