]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
abstractify items, check photos for birthday paradox
[friendica.git] / mod / wall_upload.php
1 <?php
2
3 require_once('Photo.php');
4
5 function wall_upload_post(&$a) {
6
7         if(! local_user()) {
8                 echo ( t('Permission denied.') . EOL );
9                 killme();
10         }
11
12         if(! x($_FILES,'userfile'))
13                 killme();
14
15         $src      = $_FILES['userfile']['tmp_name'];
16         $filename = basename($_FILES['userfile']['name']);
17         $filesize = intval($_FILES['userfile']['size']);
18
19         $imagedata = @file_get_contents($src);
20         $ph = new Photo($imagedata);
21
22         if(! ($image = $ph->getImage())) {
23                 echo ( t('Unable to process image.') . EOL);
24                 @unlink($src);
25                 killme();
26         }
27
28         @unlink($src);
29
30         $width = $ph->getWidth();
31         $height = $ph->getHeight();
32
33         $hash = photo_new_resource();
34         
35         $smallest = 0;
36
37         $r = $ph->store(get_uid(), 0, $hash, $filename, t('Wall Photos'), 0 );
38
39         if(! $r) {
40                 echo ( t('Image upload failed.') . EOL);
41                 killme();
42         }
43
44         if($width > 640 || $height > 640) {
45                 $ph->scaleImage(640);
46                 $r = $ph->store(get_uid(), 0, $hash, $filename, t('Wall Photos'), 1 );
47                 if($r) 
48                         $smallest = 1;
49         }
50
51         if($width > 320 || $height > 320) {
52                 $ph->scaleImage(320);
53                 $r = $ph->store(get_uid(), 0, $hash, $filename, t('Wall Photos'), 2 );
54                 if($r)
55                         $smallest = 2;
56         }
57
58         $basename = basename($filename);
59         echo  "<br /><br /><img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /><br /><br />";
60
61         killme();
62         return; // NOTREACHED
63 }