Upload file (image), with PHP to send to AWS S3

Asked

Viewed 58 times

-2

Currently I have a script that I get the image from a post like this:

$amazonS3 = new AmazonAwsS3;
$amazonS3->uploadFile($_FILES['anexo']['tmp_name'], $_FILES['anexo']['name'], "sig/$class/$idAmdamento");

but instead of me taking this file from a POST, I now need to take the file inside a directory and upload it to the amazonS3, but I’m not able to do it. tried to read with file(), readfile(), file_get_content() ex: $arquivo = readfile('../arquivos/chamados/anexo_1377633937.jpg'); but the array comes empty.... in this case I can download the image, but I can’t read the image and store it in the PHP temp to send it to another location

header('Content-Description: File Transfer');
        header('Content-Type: application/force-download');
        header ('Content-Disposition: attachment; filename='.$a->getArquivoNome().';');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header ('Content-Length: '.filesize('../arquivos/chamados/'.$a->getArquivo()));
        ob_clean();
        flush();
        readfile('../arquivos/chamados/anexo_1377633937.jpg');

someone can help me? :)

1 answer

-1


$amazonS3 = new AmazonAwsS3;
$directory = '/path/to/my/directory';
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
foreach($scanned_directory as $f){
    $amazonS3->uploadFile($directory.$f, $directory.$f, "sig/$class/$idAmdamento");
    // se for colocar o exclui file cria o unlink
    // @unlink($directory.$f);
}

In fact, you will only get the NAME OF THE SOURCE FILE AND FILE NAME AT DESTINATION not necessarily need to pass a pointer to the record and yes filenames

  • Man, thank you so much, I know the formulation of my question was not good, but you took the time to answer it and helped me very much, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.