-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathphoto_controller.php
More file actions
32 lines (31 loc) · 1.1 KB
/
Copy pathphoto_controller.php
File metadata and controls
32 lines (31 loc) · 1.1 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
<?php
require_once("Classes/FTP.Class.php");
error_reporting(0);
$file = $_FILES['Photo'];
$tempFile = $_FILES['Photo']['tmp_name'];
$targetPath = "public_html/images/uploaded/"; // FTP path
$typesArray = array("jpeg","jpg","gif","bmp","png");
$fileParts = pathinfo($_FILES['Photo']['name']);
$fileParts['extension'] = strtolower($fileParts['extension']);
if (in_array($fileParts['extension'],$typesArray))
{
//The file max size (in bytes) - It must be <= the apache max size.
$config["size"] = 1048576; // 1 MB
// Checks the image size.
if($file["size"] >= $config["size"])
{
echo '{"success": false, "msg":"The image max size is '.($config["size"]/1024).' KBytes."}';
exit;
}
// Set here how you want the final-file name. Use ways to avoid name conflicts.
$name = "image_".time().".".$fileParts['extension'];
$targetFile = str_replace('//','/',$targetPath).$name;
$ftp = new FTP($targetFile);
$ftp->Upload($targetFile, $tempFile, FTP_BINARY);
}
else
{
echo '{"success": false, "msg":"The image needs to be in the following extensions: '.(implode(",", $typesArray)).'"}';
exit;
}
?>