5

I want to send a file with javascript to php file .
I have this form in my php file

<form action="" method="post" enctype="multipart/form-data">
   <label for="file">Filename:</label>
   <input type="file" name="file" id="file1"><br>
   <p id="poi">upload</p>
   <p id="plo"></p>
</form>

and white this code in js file

jQuery(document).on("click","#poi",function(){
   var objfile=new FormData();
   var file=jQuery("#file1").get(0).files[0];
   objfile.append("iefile078",file);

   var ajax ;
   ajax.upload.addEventListener("progress" ,progresshandler ,false);
   function progresshandler(){
      jQuery("#plo").text("uploading ....");
   }
   ajax.open("POST","helper.php");
   ajax.send(objfile);
});

when I click on the "upload" on my page this function fired correctly.
I want to when upload is progressing "uploading .... " show to user.
additionally I want to send this file to helper.php file.
how to set attribute to the open() and send() function in this case to passing file uploaded to the helper.php?
this is my file structure and my form place in the default.php

js
    jquery.js
tmpl
    default.php
helper.php
mod_upload.php
mod_upload.xml
Lodder
  • 19,758
  • 10
  • 59
  • 100
adib16
  • 1,649
  • 2
  • 20
  • 35
  • You can't make an ajax call to the module files, required components controller file or external file. – Jobin Dec 19 '13 at 01:45
  • can you tell me more about that? – adib16 Dec 22 '13 at 07:17
  • you need to know basic structure of component http://stackoverflow.com/questions/19029807/what-is-difference-between-view-and-task-in-joomla-2-5-and-what-is-url-structure/19032535#19032535 , Module is the smallest unit it do not have any task(form submissions or ajax call). check the example and call your ajax according to that. – Jobin Dec 31 '13 at 03:20
  • also check this http://stackoverflow.com/questions/20853947/how-to-get-database-value-from-ajax-in-joomla-module/20854508#20854508 – Jobin Dec 31 '13 at 08:53

1 Answers1

0

Try this:

$(document).on("click","#poi", function(e) {
    e.preventDefault();
    var formData = new FormData($(this)[0]);

    $.ajax({
        url: 'helper.php',
        type: 'POST',
        data: formData,
        async: false,
        beforeSend: function() {
            $("#message1").show().html("uploading...");
        },
        success: function(data) {
            $("#message1").fadeOut();
            $("#container").html(data);
        },
        cache: false,
        contentType: false,
        processData: false
    });
});
Susheel Singh
  • 3,824
  • 5
  • 31
  • 66
  • there is no Difference beetwin my code and your code.the single difference is you use jquery and i use javascript.when we use defined( '_JEXEC' ) or die( 'Restricted access' ); in our file we can not access directory in joomla directly .my problem is how to send uploaded file from one file to another file while I can not access file in joomla directly. – adib16 Dec 22 '13 at 20:56
  • Please make your question clear by adding content which you commented here... so that others can help you. Sorry I am not aware of jhoomla :) – Susheel Singh Dec 22 '13 at 21:02
  • 1
    thank you for answer me . my code work coorectly without joomla.but when i want to use that in joomla that does not work.anyway thank you for answer – adib16 Dec 22 '13 at 21:14
  • @susheel In Joomla this will not work friend, there is no direct access to helper files in a Joomla module. – Jobin Dec 31 '13 at 03:22