mirror of
https://github.com/danpros/htmly.git
synced 2026-04-18 11:36:20 +05:30
Image Upload Feature
Adding image upload to the markdown editor using jQuery.AjaxFileUpload.js.
This commit is contained in:
parent
a2ee15a05c
commit
4c6d8c1a31
9 changed files with 568 additions and 16 deletions
45
upload.php
Normal file
45
upload.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
$whitelist = array('jpg', 'jpeg', 'png', 'gif');
|
||||
$name = null;
|
||||
$dir = 'content/images/';
|
||||
$error = null;
|
||||
$timestamp = date('YmdHis');
|
||||
$path = null;
|
||||
|
||||
if (is_dir($dir)) {
|
||||
} else {
|
||||
mkdir($dir, 0644, true);
|
||||
}
|
||||
|
||||
if (isset($_FILES)) {
|
||||
if (isset($_FILES['file'])) {
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
$name = basename($_FILES['file']['name']);
|
||||
$error = $_FILES['file']['error'];
|
||||
$path = $dir . $timestamp . '-' . $name;
|
||||
|
||||
$check = getimagesize($tmp_name);
|
||||
|
||||
if($check !== false) {
|
||||
if ($error === UPLOAD_ERR_OK) {
|
||||
$extension = pathinfo($timestamp . '-' . $name, PATHINFO_EXTENSION);
|
||||
if (!in_array($extension, $whitelist)) {
|
||||
$error = 'Invalid file type uploaded.';
|
||||
} else {
|
||||
move_uploaded_file($tmp_name, $dir . $timestamp . '-' . $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = "File is not an image.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(array(
|
||||
'path' => $path,
|
||||
'name' => $name,
|
||||
'error' => $error,
|
||||
));
|
||||
die();
|
||||
Loading…
Add table
Add a link
Reference in a new issue