Well it sounds like the file certificate.rtf does not exist in your public directory on the shared host. Simple as that
How To Fix Error file_get_contents(/home/myapp/laravel/public/invoice.rtf): failed to open stream: No such file or directory?
I use Laravel for my website. The website is already running online using shared hosting. Everything went smoothly. Except for 1 thing that still an error occurs.
I am using Novay WordTemplate to export to word dynamically.
When I run it on localhost the WordTemplate runs fine. But when I uploaded it on the hosting, an error occurred when I called mywebsite.com/word. And the route:
Route::get('/word', [DataController::class, 'word'])->name('word');
The error message that appears is :
file_get_contents(/home/mywebsite/laravel/public/certificate.rtf): failed to open stream: No such file or directory
I put the certificate.rtf file in the public_html folder. And the public_html folder is outside the laravel folder.
Here is the contents of my Controller:
public function word()
{
$file = public_path('certificate.rtf');
$array = array(
'[NUMBER]' => '015/BT/SK/V/2017',
'[COMPANY]' => 'CV. Borneo Teknomedia',
'[NAME]' => 'Melani Malik',
'[ID_COMPANY]' => '6472065508XXXX',
'[ADDRESS]' => 'Jl. Manunggal Gg. 8 Loa Bakung, Samarinda',
'[ABOUT]' => 'Application for managing Personal Identity',
'[CITY]' => 'JAKARTA',
'[DIRECTOR]' => 'Johny Deep',
'[DATE]' => date('d F Y'),
);
$nama_file = 'Certificate.doc';
return redirect()->back()->with(WordTemplate::export($file, $array, $nama_file));
}
Supposedly when I open mywebsite.com/word, a Certificate.doc file will be downloaded according to the data on the Controller. When I tried it on localhost, it was running fine. But when I upload it on the hosting why does an error occur?
Please help me solve the problem.
Please or to participate in this conversation.