В nicEdit есть функция которая добавляет с изображения по API на удалённый ресурс. Как это изменить используя PHP.
- Создайте свой файл загрузки на сервере вида:
<?php
//Check if we are getting the image
if(isset($_FILES['image'])){
//Get the image array of details
$img = $_FILES['image'];
//The new path of the uploaded image, rand is just used for the sake of it
// check
$target_file_temp = explode(".", $img['name']);
$fileExtension = strtolower(end($target_file_temp));
$allowedfileExtensions = array('jpg', 'jpeg', 'gif', 'png', 'webp', 'bmp');
if (!in_array($fileExtension, $allowedfileExtensions)) {
echo json_encode(["result"=>'Неизвестный формат файла.']);
exit();
}
// file
$newFileName = md5(time() . $img['name']) . ".{$fileExtension}";
$path = __DIR__ . "/img/announcement/" . $newFileName;
//Move the file to our new path
move_uploaded_file($img['tmp_name'],$path);
//Get image info, reuiqred to biuld the JSON object
$data = getimagesize($path);
//The direct link to the uploaded image, this might varyu depending on your script location
$link = "https://{$_SERVER['HTTP_HOST']}/ajax/img/announcement/" . $newFileName;
//Here we are constructing the JSON Object
$id = "ajax/img/announcement/{$newFileName}";
// В JSON можно оставить только необходимые поля
$res = array("status" => 200, "success" => true, "data" => array(
"id" => $id,
"deletehash" => "",
"link" => $link,
"width" => $data[0],
"height" => $data[1],
"size" => $img['size'],
"type" => $data['mime'],
"account_id" => null,
"account_url" => null,
"ad_type" => null,
"ad_url" => null,
"title" => null,
"description" => null,
"name" => "",
"views" => 0,
"section" => null,
"vote" => null,
"bandwidth" => 0,
"animated" => false,
"favorite" => false,
"in_gallery" => false,
"in_most_viral" => false,
"has_sound" => false,
"is_ad" => false,
"nsfw" => null,
"tags" => [],
"datetime" => time(),
"mp4" => "",
"hls" => ""
)
);
//echo out the response
echo json_encode($res);
}
?>
2. Найдите в коде редактора строку типа nicURI:»http://api.imgur.com/2/upload.json» и замените её на путь к своему файлу, например nicURI:»upload_img.php».
3. Проверьте загрузку.
Взято здесь, но внесены изменения в соответствии с текущими реалиями (июль 2025):
https://manzzup.blogspot.com/2014/03/customize-nicedit-image-upload-to.html