save image from jquery with json_encode from PHP

Asked

Viewed 102 times

0

I have a question when I will save the images coming from jquery with PHP json_encode.

I have this jquery code to get the images

$('#drag-and-drop-zone').dmUploader({
    url: 'upload.php',
    dataType: 'json',
    allowedTypes: 'image/*',
    /*extFilter: 'jpg;png;gif',*/
    onInit: function(){
      $.danidemo.addLog('#arquivos_cliente', 'default', 'Plugin initialized correctly');
    },
    onBeforeUpload: function(id){
      $.danidemo.addLog('#arquivos_cliente', 'default', 'Starting the upload of #' + id);

      $.danidemo.updateFileStatus(id, 'default', 'Uploading...');
    },
    onNewFile: function(id, file){
      $.danidemo.addFile('#demo-files', id, file);
    },
    onComplete: function(){
      $.danidemo.addLog('#arquivos_cliente', 'default', 'All pending tranfers completed');
    },
    onUploadProgress: function(id, percent){
      var percentStr = percent + '%';

      $.danidemo.updateFileProgress(id, percentStr);
    },
    onUploadSuccess: function(id, data){
      $.danidemo.addLog('#arquivos_cliente', 'success', 'Upload of file #' + id + ' completed');

      $.danidemo.addLog('#arquivos_cliente', 'info', 'Server Response for file #' + id + ': ' + JSON.stringify(data));

      $.danidemo.updateFileStatus(id, 'success', 'Upload Completes');

      $.danidemo.updateFileProgress(id, '100%');
    },
    onUploadError: function(id, message){
      $.danidemo.updateFileStatus(id, 'error', message);

      $.danidemo.addLog('#arquivos_cliente', 'error', 'Failed to Upload file #' + id + ': ' + message);
    },
    onFileTypeError: function(file){
      $.danidemo.addLog('#arquivos_cliente', 'error', 'File \'' + file.name + '\' cannot be added: must be an image');
    },
    onFileSizeError: function(file){
      $.danidemo.addLog('#arquivos_cliente', 'error', 'File \'' + file.name + '\' cannot be added: size excess limit');
    },
    /*onFileExtError: function(file){
      $.danidemo.addLog('#arquivos_cliente', 'error', 'File \'' + file.name + '\' has a Not Allowed Extension');
    },*/
    onFallbackMode: function(message){
      $.danidemo.addLog('#arquivos_cliente', 'info', 'Browser not supported(do something else here!): ' + message);
    }
});

I got the status with PHP json_encode

echo json_encode(array('status' => 'ok'));

How would I get the name of each image sent, so that later I can write to a folder?

  • 1

    Give a var_dump($_FILES) to upload.php and put the result here

  • returns this error Status: Syntaxerror: Unexpected token a in JSON at position 0

  • I tried echo json_encode(array( 'status' => 'ok', 'name' => $_FILES['afile']['name'] ); returned "status":"ok","name":null

  • Make a jsfiddle.net with your html and this code that sends the upload, I never used this plugin, just need to see how it sends the upload

  • https://jsfiddle.net/t5p1c2s5/ ta ai fiz sem o CSS, because I don’t think you need to understand how you pass the file, I never used this plugin tbm so my question

  • 1

    Man, I was seeing, this plugin ta without att 4 years, and there are no examples, take a look at this: http://www.dropzonejs.com/ , much easier and updated

  • Perfect Anthraxisbr !

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.