159 lines
5.1 KiB
PHP
159 lines
5.1 KiB
PHP
<?php
|
|
|
|
// inclusione del file contenente la classe
|
|
require_once "./include.php";
|
|
require_once "./myDropBoxObj.php";
|
|
|
|
use PHPImageWorkshop\ImageWorkshop;
|
|
|
|
require_once 'PHPImageWorkshop/ImageWorkshop.php'; // Be sure of the path to the class
|
|
//include "./SimpleImage.php";
|
|
|
|
$app->get('/photos/thumbnail/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app, $dirRicetteDropBox) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette from immagini where id=" . $imageID, false);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
$ext = "";
|
|
if ($retObj["type_format"] == "image/jpeg") {
|
|
$ext = "jpg";
|
|
} else if ($retObj["type_format"] == "image/png") {
|
|
$ext = "png";
|
|
}
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
|
|
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
if ($createImgTag) {
|
|
echo '<img src="';
|
|
}
|
|
echo $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
if ($createImgTag) {
|
|
echo '"/>';
|
|
}
|
|
});
|
|
|
|
$app->get('/photos/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app, $dirRicetteDropBox) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette from immagini where id=" . $imageID, false);
|
|
$mysqlconnetion->disconnetti();
|
|
$ext = "";
|
|
if ($retObj["type_format"] == "image/jpeg") {
|
|
$ext = "jpg";
|
|
} else if ($retObj["type_format"] == "image/png") {
|
|
$ext = "png";
|
|
}
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
|
|
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
if ($createImgTag) {
|
|
echo '<img src="';
|
|
}
|
|
echo $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
if ($createImgTag) {
|
|
echo '"/>';
|
|
}
|
|
});
|
|
|
|
$app->put('/photos/publish/:imageID', function ($imageID) use ($app) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$query = "update immagini set published = 1, published_date = NOW() where id = " . $imageID;
|
|
|
|
$mysqlconnetion->insertRecord($query);
|
|
$mysqlconnetion->disconnetti();
|
|
});
|
|
|
|
$app->post('/photos', function () use ($app, $dirRicetteDropBox) {
|
|
$idRicette = $app->request()->post('ricetta_id');
|
|
$profileID = $app->request()->post('keyStore');
|
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
// istanza della classe
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconneti on->connetti();
|
|
$query = "insert into immagini(id_ricette, type_format, from_profile_id, uploaded_date) " .
|
|
"values(" . $idRicette . ", '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
|
"', '" . $profileID . "', NOW())";
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
$ext = image_type_to_extension(exif_imagetype($tmpFileName), FALSE);
|
|
|
|
$imageFileName = $newID . "_full_ricetta." . $ext;
|
|
|
|
$thumbFileName = $newID . "_thumb_ricetta." . $ext;
|
|
|
|
$layer->resizeByLargestSideInPixel(640, true);
|
|
|
|
$layer->save(dirname($tmpFileName), $imageFileName);
|
|
|
|
$layer->resizeByLargestSideInPixel(300, true);
|
|
|
|
$layer->save(dirname($tmpFileName), $thumbFileName);
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
|
|
|
try {
|
|
$dropBoxObj->CreateFolder($folder);
|
|
} catch (DropboxException $ex) {
|
|
|
|
}
|
|
$fullPath = dirname($tmpFileName) . "/" . $imageFileName;
|
|
echo $fullPath . "\n";
|
|
$thumbPath = dirname($tmpFileName) . "/" . $thumbFileName;
|
|
echo $thumbPath . "\n";
|
|
$dropBoxObj->UploadFile($fullPath, $folder . "/" . $imageFileName);
|
|
|
|
$dropBoxObj->UploadFile($thumbPath, $folder . "/" . $thumbFileName);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
echo $newID;
|
|
});
|
|
|
|
$app->put('/photos/:imageID', function ($imageID) use ($app, $dirRicetteDropBox) {
|
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
// istanza della classe
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconneti on->connetti();
|
|
$query = "update immagini set (type_format = '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) . "', " .
|
|
" where id=" . $imageID;
|
|
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
|
|
$imageFileName = $imageID . "_full_ricetta";
|
|
|
|
$thumbFileName = $imageID . "_thumb_ricetta";
|
|
|
|
$layer->resizeByLargestSideInPixel(640, true);
|
|
|
|
$layer->save(dirname($tmpFileName), $imageFileName);
|
|
|
|
$layer->resizeByLargestSideInPixel(300, true);
|
|
|
|
$layer->save(dirname($tmpFileName), $thumbFileName);
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
|
|
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . DIRECTORY_SEPARATOR . $imageFileName, $folder . "\\" . $imageFileName);
|
|
|
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . DIRECTORY_SEPARATOR . $thumbFileName, $folder . "\\" . $thumbFileName);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
return $newID;
|
|
});
|