Home > database >  file_put_contents(Z:/test/39361_1657094148_elicense.pdf): failed to open stream: No such file or dir
file_put_contents(Z:/test/39361_1657094148_elicense.pdf): failed to open stream: No such file or dir

Time:07-13

I am developing a web application using laravel, and the application requires me to create a pdf file and save it to be downloaded later.I have successfully created the file from view using laravel-snappy and i can download it on the browser.The problem is that; when i try to save the file in a network shared drive using the file_put_contents function, I get the error captioned on the question's title.

When I change the path from network drive, to let say disk D:/test of the server, the file is successfully saved in that location.

I have tried the following ways to achieve it as below

$saving = "Z:/test"; Z is the network drive (drive of th shared folder)

1.By using barry laravel snappy facade

$pdf = PDF::loadView('file',compact('data'));

When I return it as below it works return $pdf->download($fileName);//download the file

But when saving it in the path it gives me the error I mentioned above $pdf->save($savePath);//saving the file

  1. Using the file_put_contents function

$output = $pdf->output();

file_put_contents($savePath,$output);

Still getting the same error

3.Using the copy function In the same drive/disk but different folders it works $path1 = "D:/files"; $path2 = "D:/test"; copy($path1,$path2);

But when i change $path2 to the shared network drive/folder

$path1 = "D:/files"; $path2 = "Z:/test"; copy($path1,$path2);

It does not work and I get a different error as shown below copy(Z:/test/39361_1657094148_elicense.pdf): failed to open stream: No such file or directory

When i change from Z:/test to IP of the shared folder as \\x.x.x.x\test it gives me another error as copy(\\x.x.x.x\test/39361_1657094148_elicense.pdf): failed to open stream: Invalid argument

I have tried this for 3 days now but nothing is working When I save to that shared folder/drive

I really need help. Anyone with an insight on how I can get out of this problem I will appreciate

Thanks in Advance

CodePudding user response:

the issue was with the permission, my application had no right to write to that network shared folder The solution was to open the directory and then save the file

I find the solution from this link https://www.codedwell.com/post/21/reading-file-list-from-a-mapped-windows-network-drive

Thanks for the insight @ADyson

  • Related