I managed to resolve. Stay tuned for space in the name of the photos. To resolve, I've changed the name of the photo from Fox na praia.jpg
, to fox_na_praia.jpg
. The complete code looks like this:
include("conectaClass.php");
class metodos{
public function __construct() {
$conectar = new conectaClass();
$this->conexao = $conectar->conectar();
return $this->conexao;
}
public function mostrarFotos(){
$sql = mysqli_query($this->conexao,"SELECT Fotos FROM pe_album_fotos");
$array = array();
while($jm = mysqli_fetch_assoc($sql)){
array_push($array,$jm["Fotos"]);
}
return $array;
}
public function deletarFotos($foto){
$sql = mysqli_query($this->conexao,"DELETE FROM pe_album_fotos WHERE Fotos = '".$foto."';");
}
public function cadastrarFotos($foto){
$sql = mysqli_query($this->conexao,"INSERT INTO pe_album_fotos VALUES(null,'".$foto."');");
}
}
Changes to the UploadHandler.php
file are in the following methods:
Line 329 (viewing photos)
protected function get_file_objects($iteration_method = 'get_file_object') {
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
return array();
}
$metodos = new metodos();
$mostrar = $metodos->mostrarFotos();
return array_values(array_filter(array_map(
array($this, $iteration_method),
$mostrar
// scandir($upload_dir)
)));
}
Line 1370 (delete)
public function delete($print_response = true) {
$file_names = $this->get_file_names_params();
if (empty($file_names)) {
$file_names = array($this->get_file_name_param());
}
$response = array();
foreach($file_names as $file_name) {
$file_path = $this->get_upload_path($file_name);
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
if ($success) {
foreach($this->options['image_versions'] as $version => $options) {
if (!empty($version)) {
$file = $this->get_upload_path($file_name, $version);
if (is_file($file)) {
unlink($file);
}
}
}
}
$metodos = new metodos();
$metodos->deletarFotos($file_name);
$response[$file_name] = $success;
}
return $this->generate_response($response, $print_response);
}
Line 1059 (Include)
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new \stdClass();
$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
$metodos = new metodos();
$mostrar = $metodos->cadastrarFotos($file->name);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
$file_size = $this->get_file_size($file_path, $append_file);
if ($file_size === $file->size) {
$file->url = $this->get_download_url($file->name);
if ($this->is_valid_image_file($file_path)) {
$this->handle_image_file($file_path, $file);
}
} else {
$file->size = $file_size;
if (!$content_range && $this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = $this->get_error_message('abort');
}
}
$this->set_additional_file_properties($file);
}
return $file;
}