3 require_once('Photo.php');
5 function wall_upload_post(&$a) {
8 notice ( "Permission denied." . EOL );
12 $src = $_FILES['userfile']['tmp_name'];
13 $filename = basename($_FILES['userfile']['name']);
14 $filesize = intval($_FILES['userfile']['size']);
16 $imagedata = @file_get_contents($src);
17 $ph = new Photo($imagedata);
19 if(! ($image = $ph->getImage())) {
20 notice("Unable to process image." . EOL);
27 $width = $ph->getWidth();
28 $height = $ph->getHeight();
30 $hash = hash('md5',uniqid(mt_rand(),true));
32 $str_image = $ph->imageString();
35 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
36 `height`, `width`, `data`, `scale` )
37 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
38 intval($_SESSION['uid']),
42 dbesc(basename($filename)),
47 notice("Image uploaded successfully." . EOL);
49 notice("Image upload failed." . EOL);
51 if($width > 640 || $height > 640) {
54 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
55 `height`, `width`, `data`, `scale` )
56 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
57 intval($_SESSION['uid']),
61 dbesc(basename($filename)),
62 intval($ph->getHeight()),
63 intval($ph->getWidth()),
64 dbesc($ph->imageString())
67 notice("Image size reduction (640) failed." . EOL );
72 if($width > 320 || $height > 320) {
75 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
76 `height`, `width`, `data`, `scale` )
77 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
78 intval($_SESSION['uid']),
82 dbesc(basename($filename)),
83 intval($ph->getHeight()),
84 intval($ph->getWidth()),
85 dbesc($ph->imageString())
88 notice("Image size reduction (320) failed." . EOL );
93 $basename = basename($filename);
95 echo "<img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" />";