Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Cómo cargar un archivo mpdf después de generarlo en el depósito s3 en php

¿Puedo cargar un archivo mpdf en el servidor s3 después de generarlo?

 $file_name = $pdf->Output(time().'_'.'E-Prescription.pdf','F');
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Suponiendo que tiene el SDK de AWS instalado en su proyecto usando composer; específicamente...

 composer require aws/aws-sdk-php

Sí, puedes, usando el contenedor de flujo de esta manera:

 require "vendor/autoload.php"; $aws_file = 's3://bucketname/foldername/your_file_name.pdf'; //the folder is optional if you have one within your bucket try { $s3->registerStreamWrapper(); $mpdf->Output($aws_file, \Mpdf\Output\Destination::FILE); } catch (S3Exception $e) { $data['error'] = $e->getMessage(); //show the error as a JSON callback that you can use for troubleshooting echo json_encode($data); exit(); }

Es posible que deba agregar permisos de escritura a su servidor web de la siguiente manera (usando el servidor Apache en Ubuntu AWS EC2):

 sudo chown -R www-data /var/www/html/vendor/mpdf/mpdf/src/Config/tmp sudo chmod -R 755 /var/www/html/vendor/mpdf/mpdf/src/Config/tmp

Luego edite el archivo ConfigVariables.php que se encuentra en:

 \vendor\mpdf\mpdf\src\Config

Cambio:

 'tempDir' => __DIR__ . '/../../tmp',

A:

 'tempDir' => __DIR__ . '/tmp',

Luego cree una carpeta vacía llamada 'tmp' en ese mismo directorio. Entonces sube con alegría.

about 4 years ago · Santiago Trujillo Report

0

// Set yours config's define("AWS_S3_KEY", "<your_key_here>"); define("AWS_S3_SECRET", "<your_secret_here>"); define("AWS_S3_REGION", "<your_region_here example:us-east-1>"); define("AWS_S3_BUCKET", "<your_bucket_folder_name_here>"); try { /* doc: https://github.com/mpdf/mpdf url/download: https://github.com/mpdf/mpdf/archive/development.zip */ require_once 'mpdf/mpdf.php'; // load yout mdf libe $mpdf = new mPDF(); // set init object mPDF $nomeArquivo = md5('cliente_01'); // set file name and cripty this $mpdf->WriteHTML("Teste upload PDF in s3 bucket"); /* doc: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_installation.html url/download: https://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.zip */ require_once 'aws/aws-autoloader.php'; // set locate yout lib AWS $aws_file = 's3://'.AWS_S3_BUCKET.'/'.$nomeArquivo.'.pdf'; $s3 = new Aws\S3\S3Client([ 'region' => AWS_S3_REGION, 'version' => 'latest', 'credentials' => [ 'key' => AWS_S3_KEY, 'secret' => AWS_S3_SECRET, ] ]); $s3->registerStreamWrapper(); $mpdf->Output($aws_file); //Send yout mPDF File in s3-file-bucket } catch (S3Exception $e) { die($e->getError().' => '.$e->getMessage(); }
about 4 years ago · Santiago Trujillo Report

0

Para hacer esto, podría usar el SDK de AWS para PHP .

Primero deberá crear un cliente utilizando las credenciales de su perfil.

 use Aws\S3\S3Client; $client = S3Client::factory(array( 'credentials' => array( 'key' => 'YOUR_AWS_ACCESS_KEY_ID', 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', ) ));

Y, si el depósito ya existe, puede cargar su archivo desde el sistema de archivos de esta manera:

 $result = $client->putObject(array( 'Bucket' => $bucket, 'Key' => $file_name, 'SourceFile' => $pathToFile ));
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!