Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-25-2012, 05:43 PM   PM User | #1
Overlord
New to the CF scene

 
Join Date: Jun 2012
Location: Tehran, Iran
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Overlord is an unknown quantity at this point
Remote Uploader

hi!
i want to create a remote uploader...
i wrote something that you see below:
PHP Code:
<html>
<head>
<title>upload.php</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>  
<script language='javascript' type="text/javascript">
   alert('2e2e');
   function do_upload()
   {
      alert('it works...!');
      var source_url=document.getElementById('url').value;
      //ajax request for remote upload
      $.ajax({
      type: "POST",
      url: "http://ektoplazm.ir/files/upload2.php",
      data: { url: source_url, submit: "Upload" }
      }).done(function( msg ) {
      alert( "Data Saved: " + msg );
      });
      //continue : update upload status
      setInterval('update_upload_status()',512);
   }

   function update_upload_status(){
      alert('upload is starting...');
      var source_url=document.getElementById('url').value;
      var destination_url=source_url.substring(source_url.lastIndexOf('/')+1);
      var sfilesize;
      var dfilesize;
      var request;
      
      request = $.ajax({
      type: "HEAD",
      url: $("#"+source_url).val(),
      success: function () {
      sfilesize=request.getResponseHeader("Content-Length"));
      }
    
      request = $.ajax({
      type: "HEAD",
      url: $("#"+destination_url).val(),
      success: function () {
      dfilesize=request.getResponseHeader("Content-Length"));
      }
    
      var progress=dfilesize/sfilesize*100;
      if (progrss==100){
         document.getElementById('progress').innerhtml='done!';
      }else{
         document.getElementById('progress').innerhtml=progress;
      }
 

   }

   
</script> 
</head>
<body>
<form action='' method="post">
<input name="url" size="50" />
<input name="upload" type="button" value='upload' onclick="javascript:do_upload();" />
</form>
<p id='progress'>progress</p>
</body>
</html>
<?php

// maximum execution time in seconds
set_time_limit (24 60 60);

if (!isset(
$_POST['submit'])) die();

// folder to save downloaded files to. must end with slash
$destination_folder '';

$url $_POST['url'];
$newfname $destination_folder basename($url);

echo 
$url;

$file fopen ($url"rb");
if (
$file) {
  
$newf fopen ($newfname"wb");

  if (
$newf)
  while(!
feof($file)) {
    
fwrite($newffread($file1024 ), 1024 );
  }
}

if (
$file) {
  
fclose($file);
}

if (
$newf) {
  
fclose($newf);
}

?>
i don't know why this code does not work correctly. javascript section does not run.
help me... i'm beginner!
Overlord is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:18 AM.


Advertisement
Log in to turn off these ads.