Laravel / Snappy: can not generate PDF or create folder - laravel

This is my code:
$offer = Offer::find($id);
$url = URL::to('/offers/view/' . $id . '/pdf');
PDF::loadFile($url)
->callSettings()
->save('/tisa/src/public/pdf/offer/Tisa-ponudba_'. $offer->code .'.pdf');
I am getting following error:
RuntimeException in AbstractGenerator.php line 517:
The output file's directory '/tisa/src/public/pdf/offer' could not be created.
Any ideas what could be wrong? I can not determine if a file can not be created or is the folder path?

Related

CI4 - Trying to move image but get error "could not move file php6WkH2s to /var/www/example.com/development.example.com/app_dir/public/ ()

I am trying to upload a file and move it to public/ folder. The file uploads without problem to writable folder, however, it is the moving to the public folder that has a problem.
Here is my code;
$update_post->move(ROOTPATH.'public/', $update_post.'.'.$fileType);
Path is correct. When I echo out echo ROOTPATH.'public/'; and then manually copy/paste, I do get to the destination directory.
Permissions correct. There are my permission on the public/ directory:
drwxr-xr-x 9 www-data www-data 4096 Jan 30 01:08 public
Any hints appreciated.
Reason:
It's because the move(string $targetPath, ?string $name = null, bool $overwrite = false) method's $name argument is invalid.
$update_post->move( ... , $update_post.'.'.$fileType);
Explanation:
Concatenating an class CodeIgniter\Files\File extends SplFileInfo instance calls the inherited SplFileInfo class's __toString() method which returns the path to the file as a string.
Note that it doesn't return the filename, which is what you're interested in.
Solution:
You should instead pass in the basename instead.
$update_post->move(
ROOTPATH . 'public/',
$update_post->getBasename()
);
Alternatively, since you're not changing the destination filename, it's cleaner to just not pass in the second parameter of the move(...) method. I.e:
$update_post->move(
ROOTPATH . 'public'
);
Addendum:
If you wish to change the destination filename to a new name, try this instead:
guessExtension()
Attempts to determine the file extension based on the trusted
getMimeType() method. If the mime type is unknown, will return null.
This is often a more trusted source than simply using the extension
provided by the filename. Uses the values in app/Config/Mimes.php to
determine extension:
$newFileName = "site_logo"; // New filename without suffixing it with a file extension.
$fileExtension = $update_post->guessExtension();
$update_post->move(
ROOTPATH . 'public',
$newFileName . (empty($fileExtension) ? '' : '.' . $fileExtension)
);
Notes:
The move(...) method returns a new File instance for the relocated file, so you must capture the result if the resulting location is needed: $newRelocatedFileInstance = $update_post->move(...);

passing image path from storage in Laravel failed

I have stored my images in storage/app/public/images.
and i have done the storage:link.
now i want to get a path for an image that exists in /images and i want to send it with an API.
i do the below to pass it to HTTP::attach():
$path = storage_path('images' . DIRECTORY_SEPARATOR . $new_file);
and then:
$response = Http::attach('new_file', file_get_contents($path))->post('http://localhost/imageresizer/service.php', $sizes);
when i dd($path), everything seems OK and i get the path i expect.
but there's the below error when i log::debug:
file_get_contents(C:\laragon\www\myblog\storage\images\SVoGGKjERVMYxy9qDciAhgOse9kzQsIuvBg64hjE.jpg): failed to open stream: No such file or directory
what's the problem with file_get_contents ?
If your file is in storage/app/public/images, you'll want to use:
$path = storage_path('app/public/images/' . $new_file);
NB the additional 'app/public/'.

TCPDF ERROR joomla virtuemart does not create the invoice

I use joomla 3.9.6, virtuemart 3.4.2, and tcpdf 1.0.7
When i try to view the invoice(pdf) or when i change order status to confirmed i get the TCPDF ERROR: Unable to create output file: \vmorders\invoices\invoice_190522TIXG01.pdf
i already have created the folders vmorders\invoices and gave it the proper permissions. (the site runs locally with wamp)
Php Error log
[22-May-2019 16:11:21 UTC] PHP Warning: fopen(): remote host file access not supported, file://\vmorders\invoices\invoice_190522TIXG01.pdf in C:\wamp64\www\byzantinemusic\libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php on line 1854
I think i have found the solution. Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php". At line 1850 remove code
$filename = 'file://'.$filename;
and substitute with this
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath) .$filename;
For Virtuemart 3.6.10:
Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php".
At line 1817 remove code:
$filename = 'file://'.$filename;
and replace with:
$filename = $filename;
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath)."/".$filename;

Laravel adds mysql in file path

I am facing a weird issue with Laravel 5.5. I am working on my local xampp server and trying to execute LOAD DATA INFILE query in controller function. But I am getting error PDOException (HY000)
SQLSTATE[HY000]: General error: 29 File 'D:\xampp\mysql\data\uploads\RDMST.csv' not found (Errcode: 2 "No such file or directory")
Currently my csv file is located at public/uploads folder. I tried various path settings for filename like
$fileCsv = 'uploads/RDMST.csv';
$fileCsv = public_path().'/uploads/RDMST.csv';
But I am getting same error and please notice the error path shows mysql\data in path. I am not getting from where it is appending this two folders in path. When I echo public path , it displays this:
D:\xampp\htdocs\tax\public
So, can you please help how to use path for load file without appending this "mysql\data" in path?
Any help is greatly appreciated.
Here is my complete controller function:
public function getCsv()
{
//echo public_path(); die;
//$fileCsv = public_path().'/uploads/RDMST.csv';
$fileCsv = 'uploads/RDMST.csv';
echo $query = "LOAD DATA INFILE '".$fileCsv."'
REPLACE
INTO TABLE tblreception
(year,
reception_number,
file_date,
file_time,
instrument_type,
#created_at,
#updated_at)
SET created_at=NOW(),updated_at=null";
DB::connection()->getPdo()->exec($query);
//return view('reception');
}
Can we not use csv file path?
Thanks

Make directory inside directory Laravel 5.4

I am trying to make a directory inside a directory using the following code:
Storage::makeDirectory('app/public' . $data['code'] . '/' . 'themes', true);
So the structure will be :
Folder 1 :
app/public/123
Folder 2:
app/public/123/themes
I have been trying for the last 2 hours. I hope somebody can help. Thanks !
You can create the directories recursively by calling makeDirectory() method
overFile` object
$result = File::makeDirectory('/path/to/directory', 0775, true);
In Your case, To create the themes directory inside storage directory
Storage::makeDirectory('themes', 0775, true);
To create a file inside the public directory
$result=File::makeDirectory('app/public/' . $data['code'] . '/' . 'themes',0755, true);
dd($result);
The problem was the path structure.
The following code worked :
Storage::makeDirectory('public/' . $data['code'] . '/' . 'themes');
In your app check what the path given in config/filesystem.php on line 44. So when you trying to create directory or a file check the storage directory

Resources