PhpFileUploader : Ajax Query

Last post 07-19-2012, 10:13 AM by JML86. 1 replies.
Sort Posts: Previous Next
  •  07-12-2012, 8:02 AM 74119

    PhpFileUploader : Ajax Query

    Hi,
     
    In demo Start uploading manually (f orm-manualstart.php) , how to modify ajax query  uploadobj.startupload() for having synchronous query (async : false) ?
     
     Currently, I coded :
    function doStart() {
    .......
    setTimeout(function(){
         uploadobj.startupload();
    },1000);
    .....
    }
     
     This is working well, but 200 ms or 1s or 2s, it depends on server !
     
    Regards,
     
     
     
  •  07-19-2012, 10:13 AM 74176 in reply to 74119

    Re: PhpFileUploader : Ajax Query

    I give some details :
    This is a form with or without attachments.
    Without the function setTimeout(), fileguidlist is null.
    1. <?php
      require_once "../phpuploader/include_phpuploader.php" ;
      /*** After the POST ***/
      if(isset($_POST['grade'])) {
          // Enregistrer les données du formulaire et générer $num
          require_once "../demandeur/enregistrer.php" ;
          // Les fonctions
          require_once "../include/fonctions.inc.php" ;
          // Déposer les fichiers uploadés - Caution : without setTimeout() : $fileguidlist is null !!!
          $fileguidlist = @$_POST["myuploader"];
          if($fileguidlist) {
              $num = $num_dossier."_" ;
              $guidlist = explode("/",$fileguidlist);
              $uploader = new PhpUploader();
              foreach($guidlist as $fileguid)
              {
                  $mvcfile = $uploader->GetUploadedFile($fileguid);
                  if($mvcfile)
                  {
                      $targetfilepath = "../savefiles/".$num.$mvcfile->FileName;
                      $targetfilepath = SupprimerAccents($targetfilepath) ;
                      $mvcfile->MoveTo($targetfilepath);
                  }
              }
          }
          // Rediriger après enregistrement
          echo "<script>window.location='ticket_psi.php?num=".$num_dossier."'</script>";
          exit() ;
      }
    2. ?>
    3. <HTML>
    4. ...
    5. <script type="text/javascript">
      function doStart(){
          if(VerifierFormulaire() != false) {
              var uploadobj = document.getElementById('myuploader');
              if (uploadobj.getqueuecount() > 0) {
                  setTimeout(function() {
                      uploadobj.startupload();
                  }, 10);
                  return false;
              }
              else {
                  var confirmer = confirm("Envoyer sans fichiers ?");
                  if(confirmer == false) {
                      return false;
                  }
              }
          }
          else {
              return false;
          }
      }
    6. </script>
    1. ....
    2. <form onSubmit="return doStart();" method="post">  
    3. .....  
    4.         <td><select name="grade"  value="">  
    5.             <option value="0">Sélectionner un grade ...</option>  
    6.             <?php affiche_grade(); ?>  
    7.             </select>  
    8.         </td>  
    9. ......  
    10.         <td><input type="reset" value="Annuler" name="annuler" />
    11.             <input type="submit" value="Envoyer" />  
    12.         </td>  
    13. ......  
    14.         <td class="firsttd">Les pièces jointes</td>  
    15.         <td><?php                
    16.                 $uploader=new PhpUploader();  
    17.                 $uploader->MaxSizeKB=10240;  
    18.                 $uploader->Name="myuploader";  
    19.                 $uploader->InsertText="Sélectionner les fichiers";  
    20.                 $uploader->AllowedFileExtensions="*.pdf,*.ods,*.odt";  
    21.                 $uploader->MultipleFilesUpload=true;  
    22.                 $uploader->ManualStartUpload=true;  
    23.                 $uploader->Render();  
    24.             ?>     
    25.             <ol id="filelist">  
    26.             </ol>   
    27.         </td>  
    28.     </tr>  
    29. .....  
    30. </form>
    31. ....
    32. </HTML>
     Regards,
     
View as RSS news feed in XML