]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
front page
[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 ( "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 ("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 = hash('md5',uniqid(mt_rand(),true));
34         
35         $str_image = $ph->imageString();
36         $smallest = 0;
37
38         $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
39                 `height`, `width`, `data`, `scale` )
40                 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
41                 intval($_SESSION['uid']),
42                 dbesc($hash),
43                 datetime_convert(),
44                 datetime_convert(),
45                 dbesc(basename($filename)),
46                 dbesc( t('Wall Photos')),
47                 intval($height),
48                 intval($width),
49                 dbesc($str_image));
50         if(! $r) {
51                 echo ("Image upload failed." . EOL);
52                 killme();
53         }
54
55         if($width > 640 || $height > 640) {
56                 $ph->scaleImage(640);
57
58                 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
59                         `height`, `width`, `data`, `scale` )
60                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
61                         intval($_SESSION['uid']),
62                         dbesc($hash),
63                         datetime_convert(),
64                         datetime_convert(),
65                         dbesc(basename($filename)),
66                         dbesc( t('Wall Photos') ),
67                         intval($ph->getHeight()),
68                         intval($ph->getWidth()),
69                         dbesc($ph->imageString())
70                 );
71                 if($r) 
72                         $smallest = 1;
73         }
74
75         if($width > 320 || $height > 320) {
76                 $ph->scaleImage(320);
77
78                 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
79                         `height`, `width`, `data`, `scale` )
80                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
81                         intval($_SESSION['uid']),
82                         dbesc($hash),
83                         datetime_convert(),
84                         datetime_convert(),
85                         dbesc(basename($filename)),
86                         dbesc( t('Wall Photos') ),
87                         intval($ph->getHeight()),
88                         intval($ph->getWidth()),
89                         dbesc($ph->imageString())
90                 );
91                 if($r)
92                         $smallest = 2;
93         }
94
95         $basename = basename($filename);
96         echo  "<br /><br /><img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /><br /><br />";
97
98         killme();
99         return; // NOTREACHED
100 }