]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
ajaxify the wall poster
[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                 notice ( "Permission denied." . EOL );
9                 return;
10         }
11
12         $src      = $_FILES['userfile']['tmp_name'];
13         $filename = basename($_FILES['userfile']['name']);
14         $filesize = intval($_FILES['userfile']['size']);
15
16         $imagedata = @file_get_contents($src);
17         $ph = new Photo($imagedata);
18
19         if(! ($image = $ph->getImage())) {
20                 notice("Unable to process image." . EOL);
21                 @unlink($src);
22                 return;
23         }
24
25         @unlink($src);
26
27         $width = $ph->getWidth();
28         $height = $ph->getHeight();
29
30         $hash = hash('md5',uniqid(mt_rand(),true));
31         
32         $str_image = $ph->imageString();
33         $smallest = 0;
34
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']),
39                 dbesc($hash),
40                 datetime_convert(),
41                 datetime_convert(),
42                 dbesc(basename($filename)),
43                 intval($height),
44                 intval($width),
45                 dbesc($str_image));
46         if($r)
47                 notice("Image uploaded successfully." . EOL);
48         else
49                 notice("Image upload failed." . EOL);
50
51         if($width > 640 || $height > 640) {
52                 $ph->scaleImage(640);
53
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']),
58                         dbesc($hash),
59                         datetime_convert(),
60                         datetime_convert(),
61                         dbesc(basename($filename)),
62                         intval($ph->getHeight()),
63                         intval($ph->getWidth()),
64                         dbesc($ph->imageString())
65                 );
66                 if($r === false)
67                         notice("Image size reduction (640) failed." . EOL );
68                 else
69                         $smallest = 1;
70         }
71
72         if($width > 320 || $height > 320) {
73                 $ph->scaleImage(320);
74
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']),
79                         dbesc($hash),
80                         datetime_convert(),
81                         datetime_convert(),
82                         dbesc(basename($filename)),
83                         intval($ph->getHeight()),
84                         intval($ph->getWidth()),
85                         dbesc($ph->imageString())
86                 );
87                 if($r === false)
88                         notice("Image size reduction (320) failed." . EOL );
89                 else
90                         $smallest = 2;
91         }
92
93         $basename = basename($filename);
94
95         echo "<img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" />";
96         killme();
97
98 }