Exemple #1
0
         $uploadOk = 0;
     }
 }
 if ($error == "" && file_exists($target_file)) {
     $error = "Sorry, file already exists.";
     $uploadOk = 0;
 }
 if ($error == "" && $_FILES["fileToUpload"]["size"] > 1000000) {
     $error = "Sorry, your file is too large.";
     $uploadOk = 0;
 }
 if ($error == "" && $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
     $error = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
     $uploadOk = 0;
 }
 if ($error == "" && $upload->checkImageExist($target_file)) {
     $error = "Image with same name exist";
     $uploadOk = 0;
 }
 if ($error == "" && $uploadOk) {
     $moved_ok = move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
     if ($moved_ok) {
         $thumb = new Imagick();
         $thumb->readImage($target_file);
         $thumb->resizeImage(420, 420, imagick::FILTER_LANCZOS, 0.9, false);
         $save_file = str_replace("../uploads/", "", $target_file);
         $thumb->writeImage($target_file);
         $error = "The file has been uploaded.";
         $upload->addImage($_SESSION["user"], $save_file);
     }
 }