v2.5.2
Giriş yap

Curl ile resim yükleme

polev
370 defa görüntülendi

Merhaba, ajax ile post ettiğim önce resize yapıp daha sonra sunucuya yüklüyorum ancak bu resize işlemini cdn sunucuma göndermek ve oraya resmi yüklemek istiyorum yardımcı olabilir misiniz?

Öncelik işlemlerim:

$file_name = $_FILES['file']['name'];
$file_name = hash('sha256', $file_name . $DataAction["barcode"]);
$tmp_name = $_FILES['file']['tmp_name'];
$json = [
    "imageName" => $file_name . ".jpeg",
    "barcode" => $DataAction["barcode"],
    "format" => "jpeg"
];
$uploadApi = json_decode(apiProduct::uploadFile($json), TRUE);
if ($uploadApi['status'] == "success") {

    /* 
            Bu kısımdan sonrasını cdn sunucumda yeniden boyutlandırmak istiyorum 
            ancak curl ile dosya tipini ve dosyayı gönderemiyorum 
    */
    function fileXLImage($file, $file_name, $new_img_width, $new_img_height)
    {
        $target_dir = dirname(__DIR__) . "/images/product/xl/";
        $target_file = $target_dir . $file_name;
        $image = new imageResize;
        $image->load($file['tmp_name']);
        $image->resize($new_img_width, $new_img_height);
        $image->save($target_file . ".jpeg");
    }
    function fileMediumImage($file, $file_name, $new_img_width, $new_img_height)
    {
        $target_dir = dirname(__DIR__) . "/images/product/m/";
        $target_file = $target_dir . $file_name;
        $image = new imageResize;
        $image->load($file['tmp_name']);
        $image->resize($new_img_width, $new_img_height);
        $image->save($target_file . ".jpeg");
    }
    function fileSmallImage($file, $file_name, $new_img_width, $new_img_height)
    {
        $target_dir = dirname(__DIR__) . "/images/product/s/";
        $target_file = $target_dir . $file_name;
        $image = new imageResize;
        $image->load($file['tmp_name']);
        $image->resize($new_img_width, $new_img_height);
        $image->save($target_file . ".jpeg");
    }
    $image_info = getimagesize($_FILES["file"]["tmp_name"]);
    $image_width = $image_info[0];
    $image_height = $image_info[1];
    if ($image_width >= $image_height) {
        $xl = 1430 / $image_width;
        $medium = 800 / $image_width;
        $small = 110 / $image_width;
        $xlWidth = $image_width * $xl;
        $xlHeight = $image_height * $xl;
        $mediumWidth = $image_width * $medium;
        $mediumHeight = $image_height * $medium;
        $smallWidth = $image_width * $small;
        $smallHeight = $image_height * $small;
        $data = fileXLImage($_FILES['file'], $file_name, $xlWidth, $xlHeight);
        $data = fileMediumImage($_FILES['file'], $file_name, $mediumWidth, $mediumHeight);
        $data = fileSmallImage($_FILES['file'], $file_name, $smallWidth, $smallHeight);
    } else {
        $xl = 1430 / $image_height;
        $medium = 900 / $image_height;
        $small = 110 / $image_height;
        $xlWidth = $image_width * $xl;
        $xlHeight = $image_height * $xl;
        $mediumWidth = $image_width * $medium;
        $mediumHeight = $image_height * $medium;
        $smallWidth = $image_width * $small;
        $smallHeight = $image_height * $small;
        $data = fileXLImage($_FILES['file'], $file_name, $xlWidth, $xlHeight);
        $data = fileMediumImage($_FILES['file'], $file_name, $mediumWidth, $mediumHeight);
        $data = fileSmallImage($_FILES['file'], $file_name, $smallWidth, $smallHeight);
    }
}

Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!