1. Go to this page and download the library: Download codeawn/image_compress library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php
if(isset($_POST['upload'])) {
try{ if(\Codeawn\image::uploadCompress(
"gambar", function ($file,$name) {
// backup original files
copy($file, "backup/".$name);
// show current progress
echo"processing : ".$name."<br>";
// build new name based date & time
$date = date("Ymd_his");
$fname = $date."_".$name;
// replace space with underscore
$fname = str_replace(" ","_",$fname);
// since compressed using imagejpeg function so rename non .jpg extension to .jpg
$fname = preg_replace('/\.(png|jpeg|gif)$/', '.jpg', $fname);
// return string filename with path
return "uploaded/".$fname;
// return false; for cancel process
}, 80, true
)===false){
throw new \Codeawn\FailException("upload failed","bad request!");
} else{
// this will show when no exception
echo"Success <br>";
}
}
catch(Codeawn\FailException $e) { echo $e->getTitle()," ",$e->getMessage();
}
} else{ echo"waiting upload ..";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.