jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

how to block the display other files (php, html) than images

Open fonder opened this issue 14 years ago • 2 comments

Thank you, great project

I use jQuery File Upload User Interface Plugin 6.6.2

but displays the files type: php, html

I'm setting jquery.fileupload-ui.js previewSourceFileTypes: /^image/(gif|jpeg|png)$/,

.htaccess ForceType application/octet-stream ...FilesMatch...gif|jpe?g|png... ForceType none ...FilesMatch...

how to block the display other files (php, html) than images

fonder avatar Mar 28 '12 12:03 fonder

how to use the code to display only photos:

<?php

$dir = './server/php/files/';
$imagesExtensions = array('jpg', 'jpeg', 'gif', 'png');
$folder = scandir($dir);

foreach($folder AS $photos) {
$fileinfo = pathinfo($photos);
    if(in_array($fileinfo['extension'], $imagesExtensions)) {   
    //print_r($photos);
    }
}

?>

in upload.class.php

protected function get_file_object($file_name)

or

protected function get_file_objects()
... scandir($this->options['upload_dir']) ...

:|

fonder avatar Apr 02 '12 18:04 fonder

Hi, it solved the problem

add upload.class.php

protected function get_file_object($file_name)

    // add code - Display File Types - variables
    $imagesExtensions = array('jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPGE', 'GIF', 'PNG');
    $fileinfo = pathinfo($file_path);    

    // add code - Display File Types - if
    //  && (in_array($fileinfo['extension'], $imagesExtensions))

all function code

protected function get_file_object($file_name) {
    $file_path = $this->options['upload_dir'].$file_name;
    // add code - Display File Types - variables
    $imagesExtensions = array('jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPGE', 'GIF', 'PNG');
    $fileinfo = pathinfo($file_path);    
    // add code - Display File Types - if
    //  && (in_array($fileinfo['extension'], $imagesExtensions))
    if (is_file($file_path) && $file_name[0] !== '.' && (in_array($fileinfo['extension'], $imagesExtensions)) ) {       
        $file = new stdClass();
        $file->name = $file_name;
        $file->size = filesize($file_path);
       $file->url = $this->options['upload_url'].rawurlencode($file->name); 
        foreach($this->options['image_versions'] as $version => $options) {
            if (is_file($options['upload_dir'].$file_name)) {
                $file->{$version.'_url'} = $options['upload_url']
                    .rawurlencode($file->name);
            }
        }
        $this->set_file_delete_url($file);
        return $file;
    }  
    return null;
}   

good luck ;)

fonder avatar Apr 02 '12 21:04 fonder