I use the following package to create PDF
https://github.com/niklasravnsborg/laravel-pdf
But in producation and in php 7.4 the case of the following error :
read of 8192 bytes failed with errno=21 Is a directory
an anyone help me?
I was expecting a PDF output
my code is :
$path_certificate = storage_path($create_certificate->template->img);
$path = $create_certificate->template->type == CertificateTypesEnum::PRINTABLE ? 'public/certificates/' : 'public/digital_certificates/';
$type_certificate = $create_certificate->template->type == CertificateTypesEnum::PRINTABLE ? 'pc' : 'dc';
$filename_pdf = auth()->id() . '_edu' . '_' . $create_certificate->education->id . '_' . $type_certificate;
$data = [
'path_cert' => $path_certificate,
'body_inner' => $body_inner,
'user_name' => auth()->user()->name,
'course_name' => $create_certificate->education->title,
'certificate_template' => $create_certificate->certificate_template,
'course_time' => $create_certificate->education->sessions_time / 60,
'score' => number_format($create_certificate->score, 0),
'tracking_code' => $create_certificate->tracking_code,
'date_created' => env('app_locale') == 'fa' ? \Morilog\Jalali\CalendarUtils::strftime('Y-m-d', strtotime($create_certificate->created_at)) : \Illuminate\Support\Carbon::create($create_certificate->created_at)->format('Y/m/d')
];
$pdf_digital = Pdf::loadView('certificate.digital.en_certificate',
$data)->setPaper('a4', 'landscape');
Related
Help :(, I'm a newbie trying out CKeditor 5 for my post form
I'm using ckeditor 5, and i'm trying to upload images in it. But, when i'm trying to load image i have a massage: Cannot upload file filename.
Where's the problem?
Init function :
ClassicEditor
.create( document.querySelector( '#body' ), {
ckfinder:{
uploadUrl: "{{ route('ckeditor.upload') .'?token=' . csrf_token()}}"
}
} )
.catch( error => {
console.error( error );
} );
PHP config :
$config['backends']['default'] = array(
'name' => 'default',
'adapter' => 'local',
'baseUrl' => config('app.url').'/userfiles/',
'root' => public_path('/userfiles/'),
'chmodFiles' => 0777,
'chmodFolders' => 0755,
'filesystemEncoding' => 'UTF-8'
);
Controller :
public function uploadImage(Request $request){
if($request -> hasFile('upload')){
$originame = $request->file('upload')->getClientOriginalName();
$fileName = pathinfo($originame, PATHINFO_FILENAME);
$extension = $request->file('upload')->getClientOriginalExtension();
$fileName = $fileName . '_' . time() . '.' . $extension;
$request->file('upload')->move(public_path('media'), $fileName);
$url = asset('media/' . $fileName);
return response()->json(['fileName' => $fileName, 'uploaded'=> 1, 'url' => $url]);
}
}
Thank you, help me :')
Hi everyone i need some help i work a program called file upload , but i dont get it what happen to the file i upload in laravel. in public folder there's a name called php4CA1.tmp every time i upload a pdf file please can anybody help me ? what is the meaning of this php4CA1.tmp or my code is wrong?
$request->validate([
'cover' => 'required',
'book' => 'required',
'name' => 'required',
'description' => 'required',
'price' => 'required|numeric'
]);
$image = $request->file('cover');
$new_name = rand() . '.' . $image->getClientOriginalExtension();
$image->move(public_path('images'),$new_name);
$book = $request->file('book');
$new_book_name = rand() . '.' . $book->getClientOriginalExtension();
$book->move(public_path('books'),$book);
$data = array(
'cover' => $new_name,
'book' => $new_book_name,
'name' => $request->name,
'description' => $request->description,
'price' => $request->price
);
Book::create($data);
Hi friend please follow as below you are passing the file instead of file name,
$book = $request->file('book');
$new_book_name = rand() . '.' . $book->getClientOriginalExtension();
$response = $book->move(public_path('books'),$new_book_name );
You are passing $book in
$book->move(public_path('books'),$book);
Use this:
$book = $request->file('book');
$new_book_name = rand() . '.' . $book->getClientOriginalExtension();
$book->move(public_path('books'),$new_book_name);
I´m trying to upload an image from my server to another one using an API.
I´ve uploaded to my server using native Storage facade and then, call the Guzzle function to upload the file to the other server.
The problem is that I can´t get the local of the file. Let´s see some code:
public function saveImage(Request $request)
{
// return $request;
$consorciado = Consorciado::where('id', '=', $request->consorciado_id)->first();
$documento = Documento::where('doc_id', '=', $request->id)->first();
$documento = new Documento();
$image = request()->file('f');
$documento->consorciado_id = $consorciado->id;
$documento->doc_id = $request->id;
$documento->tipo = $request->tipo;
$documento->remark = $request->remark;
$documento->idTematica = $request->idTematica;
$documento->field1 = $request->field1;
$documento->field2 = $request->field2;
$documento->field3 = $request->field3;
$documento->field4 = $request->field4;
$documento->field5 = $request->field5;
$filename = $consorciado->id . "_" . $documento->doc_id . "." . $image->getClientOriginalExtension();
$documento->nome = $filename;
// dd($doc);
// $file = fopen(Storage::disk('local') . '/' . file_get_contents($image), 'r');
// dd($file);
$client = new Client([
'base_uri' => 'http://gedocflex.com.br:8003/api/file',
]);
$response = $client->request('POST', 'http://gedocflex.com.br:8003/api/file', [
'multipart' => [
[
'name' => 'idTematica',
'contents' => '201'
],
[
'name' => 'f',
// 'contents' => $filename, file_get_contents($image)
'contents' => fopen('/' . $filename, file_get_contents($image), 'w+')
],
[
'name' => 'field1',
'contents' => '132.626.688-85'
],
[
'name' => 'field2',
'contents' => '7758'
],
[
'name' => 'field3',
'contents' => '404'
],
[
'name' => 'field4',
'contents' => '0'
],
[
'name' => 'field5',
'contents' => 'Marcello Dantas Correia'
],
[
'name' => 'remark',
'contents' => 'Enviando do meu servidor para o GED'
],
]
]);
return $response;
Storage::disk('local')->put('public/' . $filename, file_get_contents($image), 'public');
$documento->save(); //salva no meu banco
}
I´m using php artisan storage:link and the error is:
{message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory",…}
exception: "ErrorException"
file: "/Users/marcellopato/Sites/contemplado/app/Http/Controllers/DocumentoController.php"
line: 234
message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory"
trace: [{function: "handleError", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]
As you can see, I get the name of the file, but not its path.
What I am doing wrong?
Anyone?
Thanks in advance!
I am trying to create a buddypress through a custom plugin with the following code
if(isset($_POST['update-groups'])){
global $wpdb;
require_once("https://dev.technologyforthefuture.org/wp-load.php");
$csv_us_city_map = array_map('str_getcsv',file("https://dev.technologyforthefuture.org/wp-content/plugins/t4tf/Data_Files/uscountiesv1.0.0.csv"));
/*$groups = BP_Groups_Group::get(array(
'type'=>'alphabetical',
'per_page'=> -1
));*/
for($i =0; $i < count($csv_us_city_map); $i++){
$countyName = $csv_us_city_map[$i][0];
$stateName = $csv_us_city_map[$i][2];
$fullGroupName = $countyName . ", " . $stateName;
$groupSlug = strtolower($countyName) . "-" . strtolower($stateName);
$groupDescription = "<span style=\"font-family: Roboto, sans-serif;font-size: 13px;text-align: center\">Together we OPEN Doors to a brighter future for the students in $fullGroupName, $stateName.</span>";
//$groups = $wpdb->get_results("SELECT * FROM wp_bp_groups");
//$newGroup = $wpdb->insert("wp_bp_groups",array('creator_id' => 1, 'name' => $fullGroupName, 'slug' => $groupSlug, 'description' => $groupDescription, 'status' => 'public'));
$args = array(
'group_id' => 0,
'creator_id' => 1,
'name' => $fullGroupName,
'description' => $groupDescription,
'slug' => $groupSlug,
'status' => 'public',
'parent_id' => 0,
'enable_forum' => 0
);
$newGroup = groups_create_group($args);
}
}
I am getting this error when running this code
Fatal error: Uncaught Error: Call to undefined function groups_create_group()
I have tried as you can see to include the wp-load.php file and I have even required the file containing the function groups_create_group but it always shows this same error and I do not know why the function is undefined
SO How do I fix this error?
The path to the file that im working on is wp-content/plugins/t4tf/t4tf.php
Do not use http urls to include php files.
require_once("https://dev.technologyforthefuture.org/wp-load.php");
is plain wrong on so many levels.
Use relative or absolute file system path.
It is not clear where your code is used exactly, so I can't just give you a working code, but something like the following line should work:
require_once(__DIR__ . '/../wp-load.php');
I refer to http://samsonasik.wordpress.com/2012/08/31/zend-framework-2-creating-upload-form-file-validation/ and follow this, I can upload 1 file successfully by using rename filter in ZF2.
However when I use this way to upload 2 files, it goes wrong. I paste my code as following:
$this->add(array(
'name' => 'bigpicture',
'attributes' => array(
'type' => 'file'
),
'options' => array(
'label' => 'Big Pic'
)
));
$this->add(array(
'name' => 'smallpicture',
'attributes' => array(
'type' => 'file'
),
'options' => array(
'label' => 'Small Pic'
)
));
<div class="row"><?php echo $this->formRow($form->get('smallpicture')) ?></div>
<div class="row"><?php echo $this->formRow($form->get('bigpicture')) ?></div>
$data = array_merge(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
$form->setData($data);
if ($form->isValid()) {
$product->exchangeArray($form->getData());
$picid = $this->getProductTable()->saveProduct($product);
$pathstr = $this->md5path($picid);
$this->folder('public/images/product/'.$pathstr);
//move_uploaded_file($data['smallpicture']['tmp_name'], 'public/images/product/'.$pathstr.'/'.$picid.'_small.jpg');
//move_uploaded_file($data['bigpicture']['tmp_name'], 'public/images/product/'.$pathstr.'/'.$picid.'_big.jpg');
$fileadaptersmall = new \Zend\File\Transfer\Adapter\Http();
$fileadaptersmall->addFilter('File\Rename',array(
'source' => $data['smallpicture']['tmp_name'],
'target' => 'public/images/product/'.$pathstr.'/'.$picid.'_small.jpg',
'overwrite' => true
));
$fileadaptersmall->receive();
$fileadapterbig = new \Zend\File\Transfer\Adapter\Http();
$fileadapterbig->addFilter('File\Rename',array(
'source' => $data['bigpicture']['tmp_name'],
'target' => 'public/images/product/'.$pathstr.'/'.$picid.'_big.jpg',
'overwrite' => true
));
$fileadapterbig->receive();
}
the above are form,view,action.
using this way, only the small picture uploaed successfully. the big picture goes wrong.
a warning flashed like the following:
Warning:move_uploaded_file(C:\WINDOWS\TMP\small.jpg):failed to open stream:Invalid argument in
E:\myproject\vendor\zendframework\zendframework\library\zend\file\transfer\adapter\http.php
on line 173
Warning:move_uploaded_file():Unable to move 'C:\WINDOWS\TMP\php76.tmp'
to 'C:\WINDOWS\TEMP\big.jpg' in
E:\myproject\vendor\zendframework\zendframework\library\zend\file\transfer\adapter\http.php
on line 173
Who can tell me how to upload more than 1 file in this way. you know, the rename filter way similar to above. thanks.
I ran into the same problem with a site i did. The solution was to do the renaming in the controller itself by getting all the images and then stepping through them.
if ($file->isUploaded()) {
$pInfo = pathinfo($file->getFileName());
$time = uniqid();
$newName = $pName . '-' . $type . '-' . $time . '.' . $pInfo['extension'];
$file->addFilter('Rename', array('target' => $newName));
$file->receive();
}
Hope this helps point you in the right direction.
I encountered the same problem and i managed to make it work using the below code;
$folder = 'YOUR DIR';
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setDestination($folder);
foreach ($adapter->getFileInfo() as $info) {
$originalFileName = $info['name'];
if ($adapter->receive($originalFileName)) {
$newFilePath = $folder . '/' . $newFileName;
$adapter->addFilter('Rename', array('target' => $newFilePath,
'overwrite' => true));
}
}