3 require_once('Photo.php');
5 function wall_upload_post(&$a) {
8 echo ( "Permission denied." . EOL );
12 if(! x($_FILES,'userfile'))
15 $src = $_FILES['userfile']['tmp_name'];
16 $filename = basename($_FILES['userfile']['name']);
17 $filesize = intval($_FILES['userfile']['size']);
19 $imagedata = @file_get_contents($src);
20 $ph = new Photo($imagedata);
22 if(! ($image = $ph->getImage())) {
23 echo ("Unable to process image." . EOL);
30 $width = $ph->getWidth();
31 $height = $ph->getHeight();
33 $hash = hash('md5',uniqid(mt_rand(),true));
35 $str_image = $ph->imageString();
38 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
39 `height`, `width`, `data`, `scale` )
40 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
41 intval($_SESSION['uid']),
45 dbesc(basename($filename)),
50 echo ("Image upload failed." . EOL);
54 if($width > 640 || $height > 640) {
57 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
58 `height`, `width`, `data`, `scale` )
59 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
60 intval($_SESSION['uid']),
64 dbesc(basename($filename)),
65 intval($ph->getHeight()),
66 intval($ph->getWidth()),
67 dbesc($ph->imageString())
73 if($width > 320 || $height > 320) {
76 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
77 `height`, `width`, `data`, `scale` )
78 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
79 intval($_SESSION['uid']),
83 dbesc(basename($filename)),
84 intval($ph->getHeight()),
85 intval($ph->getWidth()),
86 dbesc($ph->imageString())
92 $basename = basename($filename);
93 echo "<br /><br /><img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /><br /><br />";