]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
enhance url parse
[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         $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                 echo ("Unable to process image." . EOL);
21                 @unlink($src);
22                 killme();
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                 echo ("Image upload failed." . EOL);
48                 killme();
49         }
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) 
67                         $smallest = 1;
68         }
69
70         if($width > 320 || $height > 320) {
71                 $ph->scaleImage(320);
72
73                 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, 
74                         `height`, `width`, `data`, `scale` )
75                         VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
76                         intval($_SESSION['uid']),
77                         dbesc($hash),
78                         datetime_convert(),
79                         datetime_convert(),
80                         dbesc(basename($filename)),
81                         intval($ph->getHeight()),
82                         intval($ph->getWidth()),
83                         dbesc($ph->imageString())
84                 );
85                 if($r)
86                         $smallest = 2;
87         }
88
89         $basename = basename($filename);
90
91         echo "<img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" />";
92         killme();
93
94 }