Permissions for calls XMLHttpRequest using the Uploadifive plugin

3

How about friends I have a problem using the Uploadifive plugin, to upload multiple images to my server, this plugin uses the XMLHttpRequest service. I have a .htaccess file that blocks the access to the directories and files, but I added the permission for AJAX, and it works correctly but not for the plugin since it generates a 403 access denied error. Checking the js of uploadifive.js I added a header but still nothing, someone solved this problem ?, I leave here my code, thanks in advance.

Code of the uploadifive.js file where I added a header of: X-Requested-With

xhr.open(settings.method, settings.uploadScript, true);
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

Code of the file where I use the plugin to send the photos:

$('#file_upload').uploadifive({
  'auto'             : false,
  //'checkScript'      : 'programacion_file_check.php',
  'formData'         : {
                         'timestamp' : '0',
                         'token'     : '0',
                         'action'    : 'insertar',
                         'gar_id' : '0'
                       },
  'queueID'          : 'queue',
  'uploadScript'     : 'http://localhost/ipdnbeta/vista/garantiafile/garantiafile_controller.php',
  'queueSizeLimit'   : 10,
  'uploadLimit'      : 10,
  'multi'            : true,
  'buttonText'       : 'Seleccionar Archivo',
  'height'           : 20,
  'width'            : 180,
  'fileSizeLimit'    : '5MB',
  'fileType'         : ["image\/gif","image\/jpeg","image\/png","image\/jpg"],
  'onUploadComplete' : function(file, data) {
    console.log(data);     
  }

finally my code in the .htaccess, where I'm allowed to AJAX, but it does not work for the uploadifive plugin:

SetEnvIfNoCase X-Requested-With XMLHttpRequest ajax                    
<Files ~ "\.(php)$">
  Order Deny,Allow
  Deny from all
  Allow from env=ajax                                                  
</Files>
    
asked by jantoni 06.02.2018 в 22:40
source

1 answer

1

The solution if someone happens the same thing, is to add a variable in your .htaccess just like the AJAX variable. It would be like this:

SetEnvIfNoCase X-Requested-With XMLHttpRequest ajax            
SetEnvIfNoCase Content-Type ".*" tipo                                  
<Files ~ "\.(php)$">
  Order Deny,Allow
  Deny from all
  Allow from env=ajax
  Allow from env=tipo                                                
</Files>
    
answered by 07.02.2018 в 21:35