0
How do I select the local image of the computer and upload it to my server which should return the image URL in Tinymce and generate the tag <img>
with the src
containing the image URL on the server?
I was reading the documentation File & Image Upload And I didn’t understand it very well. I even tried to implement it. I saw that there should be a script to handle the upload and it should return the JSON with the image address, but I didn’t understand how it will work on the client side, better as applying in Timymce.
I already have the basic back-end script ready to receive the images, but I can’t get TMCE to send them. I’m almost disillusioned and creating a gallery of images for this.
<?php
class Upload {
private $file;
private $nameInput;
private $mimeImg;
private $dir;
private $dirUpload;
private $newName;
function __construct($file, $name) {
$this->file = $file;
$this->nameInput = $name;
$this->dir = $_SERVER['DOCUMENT_ROOT'] . '/mysite/img/postagens/';
$this->dirUpload = $this->dir . date('YmdHisS-') . basename($this->file[$name]['name']);
$this->newName = '/mysite/img/postagens/' . date('YmdHisS-') . basename($this->file[$name]['name']);
$this->mimeImg = ['image/png', 'image/jpeg', 'image/gif', 'image/ico', 'image/vnd.microsoft.icon'];
}
public function getName() {
return $this->file[$this->nameInput]['name'];
}
public function getNewName() {
return $this->newName;
}
public function getDirUpload() {
return $this->dirUpload;
}
public function getType() {
return $this->file[$this->nameInput]['type'];
}
public function getSize() {
return $this->file[$this->nameInput]['size'];
}
public function getError() {
return $this->file[$this->nameInput]['error'];
}
public function setName($name) {
$this->dirUpload = $this->dir . '/' . $name;
}
public function setTmpName() {
$this->file[$this->nameInput]['tmp_name'];
}
public function setSalve() {
return move_uploaded_file($this->file[$this->nameInput]['tmp_name'], $this->dirUpload);
}
function getFile() {
return $this->file[$this->nameInput]['tmp_name'];
}
}
$upload = new Upload($_FILES, 'img');
$upload->setSalve();
header('Content-Type: application/json');
json_encode(['location',$upload->getNewName()]);
I’ve tried this js configuration and nothing happens.
– ayelsew