没有一个答案对我有用,所以我制作了一个 PHP 上传器文件,该文件检索几乎与 imgur 相同的对象。
这是文件:
上传者.php
<?php
require_once 'controllers/utils.php';
$target_image_dir = "views/images/inner_img/";
$target_file = "";
$response = array('data' => [], 'success' => false, "status" =>499 );
$fotoLink = json_encode($_FILES);
if(!empty($_FILES["image"]['tmp_name'])){
$imagen = $_FILES["image"];
list($width, $height) = getimagesize($imagen['tmp_name']);
$imageFileType = pathinfo($imagen["name"],PATHINFO_EXTENSION);
$fileNameCoded = uniqid('', false).'.'. strtolower($imageFileType);
$target_file = $target_image_dir.$fileNameCoded;
$fotoLink = $target_file;
if (move_uploaded_file($imagen["tmp_name"], $target_file)){
strtolower($imageFileType));
$littleImage = '/views/images/inner_img/'.$fileNameCoded;
$fotoLink = SITE_URL.$littleImage;
$data = array( "type"=> "image/".strtolower($imageFileType),
"width"=> $width ,
"height"=> $height,
"name"=> "",
"link"=> $fotoLink);
$response = array('data' => $data, 'success' => true, "status" => 200 );
}
}
$response = array('data' => $data, 'success' => true, "status" => 200);
echo json_encode($response);
utils.php 检查图像属性:
实用程序.php
define('KB', 1024);
define('MB', 1048576);
define('GB', 1073741824);
define('TB', 1099511627776);
define('semana', array('','Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado','Domingo'));
function checkImageAttrs($image, $targeFile)
{
if(getimagesize($image["tmp_name"]) === false)
{
return "El archivo de el archivo no es una imagen.";
}
if ($image["size"] > 10*MB)
{
return "Ups, el archivo es muy grande.";
}
$imageFileType = pathinfo($image["name"],PATHINFO_EXTENSION);
if($imageFileType!="jpg" && $imageFileType!="png" && $imageFileType!="jpeg" && $imageFileType!="gif" )
{
return "Ups, sólo están permitidos los archivos de tipo JPG, JPEG, PNG y GIF.";
}
return "OK";
}
function randomPassword($characters_count) {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $characters_count; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
警告:
如果您将其用作开放式上传器,我确信这不够安全,但我必须为受限页面执行此操作,所以它可以完成工作。
这适用于从以下网址下载的 0.9 r25 版:http: //nicedit.com/download.php