can anyone show me how to upload a binary file using Ajax (and php of course) I mean the html and js ?

Recommended Answers

All 4 Replies

I'm pretty new to AJAX so this may look like simple questions but..., so i want my file to be stored in a table in a db i have on my localhost, i'm using iframe

<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>

what source do i provide, what about the id? and this is the php code , what path do i provide in th destination path?

   <?php
   // Edit upload location here
   $destination_path = ;

   $result = 0;

   $target_path = $destination_path . basename( $_FILES['myfile']['name']);

   if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
      $result = 1;
   }

   sleep(1);
?>

<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>   
Member Avatar for LastMitch

I'm pretty new to AJAX so this may look like simple questions but..., so i want my file to be stored in a table in a db i have on my localhost, i'm using iframe

Why a <iframe>? I never seen a AJAX with a <iframe> I'm not sure it's gonna to work you can try.

Can you just used a <div> container? It makes more sense and much easier to remember that's how I used AJAX

what source do i provide, what about the id? and this is the php code , what path do i provide in th destination path?

It's incomplete because where do you want the file to be upload? That's not how you target the folder.

Member Avatar for stbuchok

If you can use HTML 5, please take a look at this:

http://www.html5rocks.com/en/tutorials/file/dndfiles/

This would allow you to chunk the file locally and send it through websockets or webservices. You would be able to upload any size file (even 4GB) without hitting any limits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.