jQuery File Upload with PHP only brings me 01 result of Mysql

0

I'm using the jQuery File Upload for a project and among the features, I'm trying to show the photos that are registered in the database. For this I am doing the following:

require_once("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;
  }
}

And in the file server/php/UploadHandler.php on line: 336, I'm doing this:

require_once("metodos.php");

class UploadHandler
{
.....
$metodos = new metodos();
$mostrar = $metodos->mostrarFotos();

return array_values(array_filter(array_map(
            array($this, $iteration_method),
                  $mostrar
          //  scandir($upload_dir)
)));
.....
}

Despite having 3 photos registered in the bank, it is only returning me 01.

When I isolate the block and give a print_r (), it usually appears:

Array ( [0] => DmCZxSRXoAIUBxZ.jpg [1] => Fox na praia.jpg )

    
asked by anonymous 16.10.2018 / 22:21

1 answer

2

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;
    }
    
16.10.2018 / 22:29