-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpostimg.php
More file actions
59 lines (59 loc) · 2.75 KB
/
postimg.php
File metadata and controls
59 lines (59 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/* ejemplo de subida de imágenes para tinymce */
require_once(__DIR__."/config.php");
$imageFolder = __DIR__."/up/";
reset ($_FILES);
$temp = current($_FILES);
if (is_uploaded_file($temp['tmp_name'])){
if (isset($_SERVER['HTTP_ORIGIN'])) {
// same-origin requests won't set an origin. If the origin is set, it must be valid.
if (in_array($_SERVER['HTTP_ORIGIN'], $sitios)) {
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
} else {
header("HTTP/1.0 403 Origin Denied");
return;
}
}
// Verify extension
if(!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png","jpeg","gif"))) {
header("HTTP/1.0 500 Invalid extension.");
return;
}
// Accept upload if there was no origin, or if it is an accepted origin
$pato = $imageFolder.date('Y/m/');
$ext = strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION));
$file = uniqid()."_o.".$ext;
$filet= str_replace("_o","",$file);
$filete=str_replace("_o","_t",$file);
//
if(!preg_match("/\.jpg$/",$filet)) { $filet = str_replace(".".$ext,".jpg",$filet); }
if(!preg_match("/\.jpg$/",$filete)) { $filete = str_replace(".".$ext,".jpg",$filete); }
//
if(!is_dir($pato)) mkdir($pato,0755,true);
//$filetowrite = $imageFolder . $temp['name'];
$filetowrite = $pato.$file;
move_uploaded_file($temp['tmp_name'], $filetowrite);
$t = `identify $filetowrite`;
$s = explode(" ",$t);
if(in_array($s[1],['JPG','JPEG','PNG','GIF'])) {
$ext = trim(strtolower($s[1]));
$ss = explode("x",$s[2]);
if($ss[0]>=720 && $ext!='gif') {
//
$cmd = "convert -thumbnail 720 -flatten -quality 70 -background white -auto-orient ".$filetowrite."[0] ".$pato.$filet; $cmd = `$cmd`;
$cmd = "convert -thumbnail 200 -flatten -quality 60 ".$pato.$filet." ".$pato.$filete; $cmd = `$cmd`;
$size=720;
} elseif($ss[0]>=200 && $ext!='gif') {
$cmd = "convert -thumbnail ".$ss[0]." -flatten -quality 70 -background white -auto-orient ".$filetowrite."[0] ".$pato.$filet; $cmd = `$cmd`;
$cmd = "convert -thumbnail 200 -flatten -quality 60 ".$pato.$filet." ".$pato.$filete; $cmd = `$cmd`;
$size=$ss[0];
} else {
if(!empty($ss[0])) $size=$ss[0];
copy($filetowrite,$filet);
$cmd = "convert -thumbnail 200 -flatten -quality 60 -background white ".$filetowrite."[0] ". $pato.$filete; $cmd = `$cmd`;
}
echo json_encode(array('location' => $sitio."up/".date('Y/m/').$filet));
}
} else {
header("HTTP/1.0 500 Server Error");
}