CMS  Version 3.9
photo_upload.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("image");
3 
4 $gallery_id = checkNumeric($_GET["gallery_id"]);
5 
6 trace(print_r($_FILES, true), 2);
7 
8 if (!$gallery_id)
9 {
10  Fakoli::end("Invalid Parameter");
11 }
12 
13 if (!isset($_FILES["photo"]))
14 {
15  Fakoli::end("No photo present in upload");
16 }
17 
19 
20 if ($gallery->owner_id != $user->get($user->getPrimaryKey()) && !checkRole($gallery->write_access))
21 {
22  Fakoli::end("Permission Denied");
23 }
24 
25 //Fudge: Deal with uploads that have no file extension
26 if (!preg_match("/\\.\\w+$/", $_FILES["photo"]["name"]))
27 {
28  if (ImageManager::isJPG($_FILES["photo"]["tmp_name"]))
29  {
30  $_FILES["photo"]["name"] .= ".jpg";
31  }
32  else if (ImageManager::isPNG($_FILES["photo"]["tmp_name"]))
33  {
34  $_FILES["photo"]["name"] .= ".png";
35  }
36  else
37  {
38  Fakoli::end("Unsupported image format");
39  }
40 }
41 
43 $image->gallery_id = $gallery_id;
44 $image->title = "Uploaded Photo";
45 $image->ALT_tag = "Uploaded Photo";
46 $image->date_taken = now();
47 $image->credits = $user->getFullName();
48 $image->caption = "";
49 $image->keywords = "";
50 $image->related_resource = "";
51 $image->published = false;
52 $image->include_in_slideshow = false;
53 $image->sort_order = 0;
54 $image->image_type = $_FILES["photo"]["type"];
55 $image->owner_id = $user->get($user->getPrimaryKey());
56 
58 
59 $image->save();
60 
61 Fakoli::end($image->image_id);
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static isJPG($filename)
Test the contents of the specified file, returning true if a JPEG header signature is found.
static imageUploadHandler($field, $image)
Upload the image file specified in the given field.
static isPNG($filename)
Test the contents of the specified file, returning true if a PNG header signature is found.
global $user
$gallery_id
Definition: photo_upload.inc:4
if(! $gallery_id) if(!isset($_FILES["photo"])) $gallery
if($gallery->owner_id !=$user->get($user->getPrimaryKey()) &&!checkRole($gallery->write_access)) if(!preg_match("/\\.\\w+$/", $_FILES["photo"]["name"])) $image