I have a problem with Joining 2 functions, So I am use https://github.com/spatie/pdf-to-image - this function for convert uploaded pdf(s) to image(s). this is working fine, but this function uploads converted images to the local directory, but i want to change it and save converted images to the yandex disk not a local directory. my function with curl for upload files to yandex disk working fine too, but i dont know how to join this 2 functions,
I want to change $pdf->setPage($pageNumber)->saveImage($pageNumber . '.jpg');
to uploadtoyandexdisk("folder", "", $pageNumber . '.jpg');
for uploading to yandex disk, can you help ?
//edited code
if(!empty($_FILES["fileToUpload"])){
error_reporting(E_ALL);
ini_set("display_errors", 1);
function uploadtoyandexdisk($folder, $file, $name) {
if(empty($file)){
$filename = $name;
$filepath = $_FILES["fileToUpload"]["tmp_name"];
} else{
$filename = $name;
$filepath = $file;
}
$yandexusername = "username";
$yandexpassword = "password";
$credentials = array($yandexusername,$yandexpassword);
$filesize = filesize($filepath);
$fh = fopen($filepath, 'r');
$remoteUrl = 'https://webdav.yandex.ru/uploads/'.$folder.'/';
$ch = curl_init($remoteUrl . $filename);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, implode(':', $credentials));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, $filesize);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response=curl_exec($ch);
fclose($fh);
echo $response;
}
include "../inc/extensions/pdftoimage/Pdf.php";
$pdf = new Spatie\PdfToImage\Pdf($_FILES["fileToUpload"]["tmp_name"]);
foreach (range(1, $pdf->getNumberOfPages()) as $pageNumber) {
$pdf->setCompressionQuality(50);
$pdf->setPage($pageNumber)
->saveImage($pageNumber . '.jpg');
$imgdata = $pdf->setPage($pageNumber)->getImageData($pageNumber . '.jpg');
uploadtoyandexdisk("uploads", $imgdata, $pageNumber . '.jpg');
}
}