本文整理匯總了PHP中ImageManager::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::add方法的具體用法?PHP ImageManager::add怎麽用?PHP ImageManager::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ImageManager
的用法示例。
在下文中一共展示了ImageManager::add方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: action_validePhoto
public function action_validePhoto()
{
$extensions = array("png", "jpg", "jpeg", "bmp", "PNG", "JPG", "JPEG", "BMP");
$taille_max = 100000;
$dossier = "images/";
$fichier = uniqid();
$extension = explode('.', $_FILES['photo']['name']);
$extension = strtolower($extension[count($extension) - 1]);
if (!in_array($extension, $extensions)) {
$error[] = "mauvaise extension";
}
/*$taille = getimagesize($_FILES['photo']['tmp_name']);
$larg=300;
$reduc=($larg*100)/$taille[0];
$haut=($taille[1]*$reduc)/100;
if($extension!="jpg")
$function=imagecreatefrom.$extension;
else $function=imagecreatefrom.jpeg;
$image=imagecreatetruecolor($larg,$haut);
imagecopyresampled($image, $function($_FILES['photo']['tmp_name']), 0, 0, 0, 0, $larg, $haut, $taille[0],$taille[1]);
imagepng($image,$dossier.$fichier.".png",9);*/
move_uploaded_file($_FILES['photo']['tmp_name'], $dossier . $fichier . ".jpg");
if (isset($error[0])) {
$f = $this->session->formPh;
$f->populate();
$this->tpl->assign("f_addph", $f);
foreach ($error as $err) {
$this->site->ajouter_message("-" . $err);
}
} else {
$img['idImage'] = $fichier;
$img['idModele'] = $this->req->id;
$image = new Image($img);
$imgM = new ImageManager(DB::get_instance());
$imgM->add($image);
$this->site->ajouter_message("upload réussi");
//il faudra penser à redimensionner la photo
Site::redirect("admMarque");
}
}
示例2: htmlentities
$typeMessage = "";
$idProjet = htmlentities($_POST['idProjet']);
//Component Class Manager
$imageManager = new ImageManager($pdo);
//Action Add Processing Begin
if ($action == "add") {
if (!empty($_POST['name'])) {
$name = htmlentities($_POST['name']);
$url = htmlentities($_POST['url']);
$description = htmlentities($_POST['description']);
$createdBy = $_SESSION['userAnnahdaSite']->login();
$created = date('Y-m-d h:i:s');
//create object
$image = new Image(array('name' => $name, 'url' => $url, 'description' => $description, 'idProjet' => $idProjet, 'created' => $created, 'createdBy' => $createdBy));
//add it to db
$imageManager->add($image);
$actionMessage = "<strong>Opération Valide</strong> : Image Ajouté(e) avec succès.";
$typeMessage = "success";
} else {
$actionMessage = "<strong>Erreur Ajout Image</strong> : Vous devez remplir le champ 'name'.";
$typeMessage = "danger";
}
} else {
if ($action == "update") {
$idImage = htmlentities($_POST['idImage']);
if (!empty($_POST['name'])) {
$name = htmlentities($_POST['name']);
$url = htmlentities($_POST['url']);
$description = htmlentities($_POST['description']);
$idProjet = htmlentities($_POST['idProjet']);
$updatedBy = $_SESSION['userAnnahdaSite']->login();
示例3: receiveImage
public function receiveImage()
{
//$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
$result = array('success' => false, 'message' => 'Upload error', 'status' => 'error', 'total' => 0, 'records' => array());
// Get filename and img base64 string from request
$fileName = $this->f3->get('PARAMS.fileName');
$img = $this->f3->get('POST.img');
// Return error message if file size is too big. Hint: base64 increase file size ~33%
if (strlen($img) > 512 * 1024 * 1.4) {
$result[message] = 'File size too big. <b>Size:' . round(strlen($img) / 1024) . 'KB</b>';
} else {
$url = $this->f3->get('UPLOAD') . $fileName;
// Make sure file not already exists
if (file_exists($url) == false) {
// Get file data to perform check if file is image
list($type, $data) = explode(';', $img);
if (in_array($type, array('data:image/png', 'data:image/jpg', 'data:image/gif', 'data:image/jpeg'))) {
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents($url, $data);
// clear POST and copy variable to insert
$this->f3->clear('POST');
$this->f3->set('POST.imageName', $fileName);
$this->f3->set('POST.imageLink', $url);
$this->f3->set('POST.size', strlen($data));
// Add reference to db
$image = new ImageManager($this->db);
$image->add();
$result[success] = true;
$result[status] = 'success';
$result[message] = 'Successfully uploaded. File size: ' . round(strlen($data) / 1024) . 'KB';
}
} else {
$result[message] = 'File already exists';
}
}
header('Content-Type: application/json');
echo json_encode($result, JSON_NUMERIC_CHECK);
exit;
}