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