943,022 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 283
  • PHP RSS
Aug 16th, 2010
0

Can anyone correct this php remote file upload script?

Expand Post »
Hello everyone..
I have a open source remote file upload script. It is called file snatcher. We can directly upload the files to our server from another server. But the problem is we can upload only one file at a time. I mean if you have many url, you have to enter the second url after first one finished. I have almost 500 url to upload in my server. So i need little correction in this script.
Instead of single url, i want to enter a bunch of url and upload it. I know it is a little correction something like "foreach" loop. But i don't know exactly how to correct it. Because i know php only little bit. So can anyone help me?. I have attached the source codes.

settings.php
PHP Syntax (Toggle Plain Text)
  1. /*settings.php*/
  2. <?php
  3. defined('_ALLOWINCLUDE') or die();
  4.  
  5. // Default destination to copy files too NO TRAILING SLASH!!
  6. // If it is complete path, file be copied there ex: /home/public_html/FOLDER (Linux), C:\htdocs\FOLDER (Windows)
  7. // If it is just a direcotory it will be copied to that directory in directory the script is in ex: /SnatcherFolder/FOLDER
  8. $defaultDest = 'snatched';
  9. /*
  10. More examples
  11. If $defaultDest = ''; it will automatically copy to the `snatched` directory inside of the script's directory.
  12. If $defaultDest = 'files'; it will copy to `files` directory inside of the script's directory.
  13. */
  14.  
  15. // If you want a password to be required
  16. // Remember if you don't have a password anyone can copy a file to your server!
  17. $password = '';
  18.  
  19. // URL to location of snatched files WITH OUT TRAILING SLASH
  20. $URLDest = 'http://example.com/snatched';
  21.  
  22.  
  23. // Put a limit for file size in kilobytes (1024KB is 1MB)
  24. // For unlimited put 0
  25. // Example $sizelimit = 25;
  26. $sizelimit = 0;
  27.  
  28. ?>

index.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //File Snatcher 2.7
  3. define('_ALLOWINCLUDE',0);
  4. include 'settings.php';
  5. $version = '2.7';
  6. //////////////////////////////////////////////
  7. //Do Not Change Below Here////////////////////
  8. //////////////////////////////////////////////
  9. if (function_exists('curl_init'))
  10. {
  11. $snatch_system = 'curl';
  12. }
  13. ?>
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="style.css">
  18. <title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
  19. </head>
  20. <body>
  21.  
  22. <div id="main">
  23. <?php
  24. $submit = $_POST['submit'];
  25. if ($submit)
  26. {
  27. if (isset($password))
  28. {
  29. if ($_POST['password'] != $password)
  30. {
  31. die('<p><strong>Password incorrect!</strong></p>');
  32. $error = true;
  33. }
  34. }
  35.  
  36. if (!$defaultDest)
  37. {
  38. $defaultDest = 'snatched';
  39. }
  40.  
  41. if (!file_exists($defaultDest))
  42. {
  43. mkdir($defaultDest);
  44. }
  45.  
  46. $sizelimit = $sizelimit * 1024;
  47.  
  48. $file = $_POST['file'];
  49.  
  50. $uploadfile = explode('/', $file);
  51. $filename = array_pop($uploadfile);
  52.  
  53. $newfilename = $_POST['new'];
  54.  
  55. if (!$newfilename)
  56. {
  57. $newfilename = $filename;
  58. }
  59.  
  60. if (!isset($file))
  61. {
  62. echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
  63. $error = true;
  64. }
  65.  
  66. if (!isset($newfilename))
  67. {
  68. echo '<p><strong>Please enter a new file name!</strong></p>';
  69. $error = true;
  70. }
  71.  
  72. if ($error == false)
  73. {
  74. $dest = $defaultDest;
  75. $ds = array($dest, '/', $newfilename);
  76. $ds = implode('', $ds);
  77. $newname_count = 0;
  78. if (file_exists($ds))
  79. {
  80. echo '<p><strong>File already exists!</strong></p>';
  81. $newname_count++;
  82. $newfile = array($newname_count, $newfilename);
  83. $newfile = implode('~', $newfile);
  84. $newfile_ds = array($dest, '/', $newfile);
  85. $newfile_ds = implode('', $newfile_ds);
  86. while($renamed == false)
  87. {
  88. if (file_exists($newfile_ds))
  89. {
  90. $newname_count++;
  91. $newfile = array($newname_count, $newfilename);
  92. $newfile = implode('~', $newfile);
  93. $newfile_ds = array($dest, '/', $newfile);
  94. $newfile_ds = implode('', $newfile_ds);
  95. }
  96. else
  97. {
  98. $renamed = true;
  99. }
  100. }
  101. $newfilename = $newfile;
  102. $ds = $newfile_ds;
  103. echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
  104. }
  105. echo '<p><strong>Copying...</strong></p>';
  106. if ($snatch_system == 'curl')
  107. {
  108. $ch = curl_init($file);
  109. $fp = fopen($ds, 'w');
  110. curl_setopt($ch, CURLOPT_FILE, $fp);
  111. curl_setopt($ch, CURLOPT_HEADER, 0);
  112. curl_exec($ch);
  113. $curl_info = curl_getinfo($ch);
  114. curl_close($ch);
  115. fclose($fp);
  116. }
  117. else
  118. {
  119. if (!copy($file, $ds))
  120. {
  121. echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
  122. $copy_fail = true;
  123. }
  124. }
  125.  
  126. if ($copy_fail == false)
  127. {
  128. if ($sizelimit > 0 && filesize($ds) > $sizelimit)
  129. {
  130. echo '<p><strong>File is too large.</strong>';
  131. unlink($ds);
  132. }
  133. else
  134. {
  135. echo '<p><strong>Copy successful!</strong></p>';
  136. echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
  137. if ($snatch_system == 'curl')
  138. {
  139. $size_dl = round($curl_info['size_download']/1024, 2);
  140. $speed_dl = round($curl_info['speed_download']/1024, 2);
  141. echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
  142. }
  143. }
  144. }
  145. }
  146. }
  147.  
  148. $self = $_SERVER['PHP_SELF'];
  149. echo '<form method="POST" action="'.$self.'">';
  150. echo '<fieldset><legend>File Snatcher</legend>';
  151. echo '<label for="file">Full path to file to copy</label>';
  152. echo '<p>Example: http://foobar.com/image.png</p>';
  153. echo '<input type="text" name="file" id="file" size="45" value="">';
  154. echo '<label for="new">New file name (Optional)</label><br />';
  155. echo '<p>Example: image.png</p>';
  156. echo '<input type="text" name="new" id="new" size="45" value="">';
  157. if (isset($password))
  158. {
  159. echo '<label for="password">Password</label>';
  160. echo '<input type="password" name="password" id="password" size="45" value=""><br />';
  161. }
  162. echo '<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>';
  163. echo '</fieldset></form>';
  164. ?>
  165. </div>
  166. </body>
  167. </html>

Please help me guys. Thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Viruthagiri is offline Offline
38 posts
since Mar 2010
Aug 16th, 2010
1
Re: Can anyone correct this php remote file upload script?
Here is code for index.php.
check it, hope it is what you want.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //File Snatcher 2.7
  3. define('_ALLOWINCLUDE',0);
  4. include 'setting.php';
  5. $version = '2.7';
  6. //////////////////////////////////////////////
  7. //Do Not Change Below Here////////////////////
  8. //////////////////////////////////////////////
  9. if (function_exists('curl_init'))
  10. {
  11. $snatch_system = 'curl';
  12. }
  13. ?>
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="style.css">
  18. <title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
  19. </head>
  20. <body>
  21.  
  22. <div id="main">
  23. <?php
  24. $submit = $_POST['submit'];
  25. if ($submit)
  26. {
  27. if (isset($password))
  28. {
  29. if ($_POST['password'] != $password)
  30. {
  31. die('<p><strong>Password incorrect!</strong></p>');
  32. $error = true;
  33. }
  34. }
  35.  
  36. if (!$defaultDest)
  37. {
  38. $defaultDest = 'snatched';
  39. }
  40.  
  41. if (!file_exists($defaultDest))
  42. {
  43. mkdir($defaultDest);
  44. }
  45.  
  46. $sizelimit = $sizelimit * 1024;
  47.  
  48. $files = $_POST['file'];
  49. $news = $_POST['new'];
  50.  
  51. for($i=0;$i<count($files);$i++)
  52. {
  53.  
  54. $file = $files[$i];
  55. $uploadfile = explode('/', $file);
  56. $filename = array_pop($uploadfile);
  57.  
  58. $newfilename = $news[$i];
  59.  
  60. if (!$newfilename)
  61. {
  62. $newfilename = $filename;
  63. }
  64.  
  65. if (!isset($file))
  66. {
  67. echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
  68. $error = true;
  69. }
  70.  
  71. if (!isset($newfilename))
  72. {
  73. echo '<p><strong>Please enter a new file name!</strong></p>';
  74. $error = true;
  75. }
  76.  
  77. if ($error == false)
  78. {
  79. $dest = $defaultDest;
  80. $ds = array($dest, '/', $newfilename);
  81. $ds = implode('', $ds);
  82. $newname_count = 0;
  83. if (file_exists($ds))
  84. {
  85. echo '<p><strong>File already exists!</strong></p>';
  86. $newname_count++;
  87. $newfile = array($newname_count, $newfilename);
  88. $newfile = implode('~', $newfile);
  89. $newfile_ds = array($dest, '/', $newfile);
  90. $newfile_ds = implode('', $newfile_ds);
  91. while($renamed == false)
  92. {
  93. if (file_exists($newfile_ds))
  94. {
  95. $newname_count++;
  96. $newfile = array($newname_count, $newfilename);
  97. $newfile = implode('~', $newfile);
  98. $newfile_ds = array($dest, '/', $newfile);
  99. $newfile_ds = implode('', $newfile_ds);
  100. }
  101. else
  102. {
  103. $renamed = true;
  104. }
  105. }
  106. $newfilename = $newfile;
  107. $ds = $newfile_ds;
  108. echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
  109. }
  110. echo '<p><strong>Copying...</strong></p>';
  111. if ($snatch_system == 'curl')
  112. {
  113. $ch = curl_init($file);
  114. $fp = fopen($ds, 'w');
  115. curl_setopt($ch, CURLOPT_FILE, $fp);
  116. curl_setopt($ch, CURLOPT_HEADER, 0);
  117. curl_exec($ch);
  118. $curl_info = curl_getinfo($ch);
  119. curl_close($ch);
  120. fclose($fp);
  121. }
  122. else
  123. {
  124. if (!copy($file, $ds))
  125. {
  126. echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
  127. $copy_fail = true;
  128. }
  129. }
  130.  
  131. if ($copy_fail == false)
  132. {
  133. if ($sizelimit > 0 && filesize($ds) > $sizelimit)
  134. {
  135. echo '<p><strong>File is too large.</strong>';
  136. unlink($ds);
  137. }
  138. else
  139. {
  140. echo '<p><strong>Copy successful!</strong></p>';
  141. echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
  142. if ($snatch_system == 'curl')
  143. {
  144. $size_dl = round($curl_info['size_download']/1024, 2);
  145. $speed_dl = round($curl_info['speed_download']/1024, 2);
  146. echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
  147. }
  148. }
  149. }
  150. }
  151.  
  152. }
  153. }
  154.  
  155. $self = $_SERVER['PHP_SELF'];
  156. ?>
  157.  
  158. <fieldset><legend>File Snatcher</legend>
  159. <label for="file">Full path to file to copy</label>
  160. <p>Example: http://foobar.com/image.png</p>
  161. <?
  162. $repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
  163. ?>
  164. <form method="POST" action="<?=$self?>">
  165. <input type="text" name="repeat" size="10" value="<?=$repeat;?>">
  166. <input name="Repeat" value="Repeat" type="submit">
  167. </form>
  168.  
  169. <form method="POST" action="<?=$self?>">
  170. <? for($i=0;$i<$repeat;$i++){?>
  171. <br>File<?=($i+1)?> : <input type="text" name="file[]" size="45" value="">
  172. <input type="text" name="new[]" size="45" value="">
  173. <? } ?>
  174.  
  175. <label for="new">New file name (Optional)</label><br />
  176. <p>Example: image.png</p>
  177.  
  178. <? if (isset($password)){ ?>
  179.  
  180. <label for="password">Password</label>
  181. <input type="password" name="password" id="password" size="45" value=""><br />
  182. <? } ?>
  183. <p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
  184. </form>
  185. </fieldset>
  186.  
  187. </div>
  188. </body>
  189. </html>
Reputation Points: 154
Solved Threads: 162
Master Poster
vibhadevit is offline Offline
791 posts
since Apr 2010
Aug 17th, 2010
0
Re: Can anyone correct this php remote file upload script?
Dude you helped me a lot. Really awesome. Thanks for your help.
Click to Expand / Collapse  Quote originally posted by vibhadevit ...
Here is code for index.php.
check it, hope it is what you want.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //File Snatcher 2.7
  3. define('_ALLOWINCLUDE',0);
  4. include 'setting.php';
  5. $version = '2.7';
  6. //////////////////////////////////////////////
  7. //Do Not Change Below Here////////////////////
  8. //////////////////////////////////////////////
  9. if (function_exists('curl_init'))
  10. {
  11. $snatch_system = 'curl';
  12. }
  13. ?>
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="style.css">
  18. <title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
  19. </head>
  20. <body>
  21.  
  22. <div id="main">
  23. <?php
  24. $submit = $_POST['submit'];
  25. if ($submit)
  26. {
  27. if (isset($password))
  28. {
  29. if ($_POST['password'] != $password)
  30. {
  31. die('<p><strong>Password incorrect!</strong></p>');
  32. $error = true;
  33. }
  34. }
  35.  
  36. if (!$defaultDest)
  37. {
  38. $defaultDest = 'snatched';
  39. }
  40.  
  41. if (!file_exists($defaultDest))
  42. {
  43. mkdir($defaultDest);
  44. }
  45.  
  46. $sizelimit = $sizelimit * 1024;
  47.  
  48. $files = $_POST['file'];
  49. $news = $_POST['new'];
  50.  
  51. for($i=0;$i<count($files);$i++)
  52. {
  53.  
  54. $file = $files[$i];
  55. $uploadfile = explode('/', $file);
  56. $filename = array_pop($uploadfile);
  57.  
  58. $newfilename = $news[$i];
  59.  
  60. if (!$newfilename)
  61. {
  62. $newfilename = $filename;
  63. }
  64.  
  65. if (!isset($file))
  66. {
  67. echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
  68. $error = true;
  69. }
  70.  
  71. if (!isset($newfilename))
  72. {
  73. echo '<p><strong>Please enter a new file name!</strong></p>';
  74. $error = true;
  75. }
  76.  
  77. if ($error == false)
  78. {
  79. $dest = $defaultDest;
  80. $ds = array($dest, '/', $newfilename);
  81. $ds = implode('', $ds);
  82. $newname_count = 0;
  83. if (file_exists($ds))
  84. {
  85. echo '<p><strong>File already exists!</strong></p>';
  86. $newname_count++;
  87. $newfile = array($newname_count, $newfilename);
  88. $newfile = implode('~', $newfile);
  89. $newfile_ds = array($dest, '/', $newfile);
  90. $newfile_ds = implode('', $newfile_ds);
  91. while($renamed == false)
  92. {
  93. if (file_exists($newfile_ds))
  94. {
  95. $newname_count++;
  96. $newfile = array($newname_count, $newfilename);
  97. $newfile = implode('~', $newfile);
  98. $newfile_ds = array($dest, '/', $newfile);
  99. $newfile_ds = implode('', $newfile_ds);
  100. }
  101. else
  102. {
  103. $renamed = true;
  104. }
  105. }
  106. $newfilename = $newfile;
  107. $ds = $newfile_ds;
  108. echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
  109. }
  110. echo '<p><strong>Copying...</strong></p>';
  111. if ($snatch_system == 'curl')
  112. {
  113. $ch = curl_init($file);
  114. $fp = fopen($ds, 'w');
  115. curl_setopt($ch, CURLOPT_FILE, $fp);
  116. curl_setopt($ch, CURLOPT_HEADER, 0);
  117. curl_exec($ch);
  118. $curl_info = curl_getinfo($ch);
  119. curl_close($ch);
  120. fclose($fp);
  121. }
  122. else
  123. {
  124. if (!copy($file, $ds))
  125. {
  126. echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
  127. $copy_fail = true;
  128. }
  129. }
  130.  
  131. if ($copy_fail == false)
  132. {
  133. if ($sizelimit > 0 && filesize($ds) > $sizelimit)
  134. {
  135. echo '<p><strong>File is too large.</strong>';
  136. unlink($ds);
  137. }
  138. else
  139. {
  140. echo '<p><strong>Copy successful!</strong></p>';
  141. echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
  142. if ($snatch_system == 'curl')
  143. {
  144. $size_dl = round($curl_info['size_download']/1024, 2);
  145. $speed_dl = round($curl_info['speed_download']/1024, 2);
  146. echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
  147. }
  148. }
  149. }
  150. }
  151.  
  152. }
  153. }
  154.  
  155. $self = $_SERVER['PHP_SELF'];
  156. ?>
  157.  
  158. <fieldset><legend>File Snatcher</legend>
  159. <label for="file">Full path to file to copy</label>
  160. <p>Example: http://foobar.com/image.png</p>
  161. <?
  162. $repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
  163. ?>
  164. <form method="POST" action="<?=$self?>">
  165. <input type="text" name="repeat" size="10" value="<?=$repeat;?>">
  166. <input name="Repeat" value="Repeat" type="submit">
  167. </form>
  168.  
  169. <form method="POST" action="<?=$self?>">
  170. <? for($i=0;$i<$repeat;$i++){?>
  171. <br>File<?=($i+1)?> : <input type="text" name="file[]" size="45" value="">
  172. <input type="text" name="new[]" size="45" value="">
  173. <? } ?>
  174.  
  175. <label for="new">New file name (Optional)</label><br />
  176. <p>Example: image.png</p>
  177.  
  178. <? if (isset($password)){ ?>
  179.  
  180. <label for="password">Password</label>
  181. <input type="password" name="password" id="password" size="45" value=""><br />
  182. <? } ?>
  183. <p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
  184. </form>
  185. </fieldset>
  186.  
  187. </div>
  188. </body>
  189. </html>
Reputation Points: 10
Solved Threads: 0
Light Poster
Viruthagiri is offline Offline
38 posts
since Mar 2010
Aug 18th, 2010
1
Re: Can anyone correct this php remote file upload script?
Here is you code(with example form filled) to insert all URL at a time:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //File Snatcher 2.7
  3. define('_ALLOWINCLUDE',0);
  4. include 'setting.php';
  5. $version = '2.7';
  6. //////////////////////////////////////////////
  7. //Do Not Change Below Here////////////////////
  8. //////////////////////////////////////////////
  9. if (function_exists('curl_init'))
  10. {
  11. $snatch_system = 'curl';
  12. }
  13. ?>
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="style.css">
  18. <title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
  19. </head>
  20. <body>
  21.  
  22. <div id="main">
  23. <?php
  24. $submit = $_POST['submit'];
  25. if ($submit)
  26. {
  27. if (isset($password))
  28. {
  29. if ($_POST['password'] != $password)
  30. {
  31. die('<p><strong>Password incorrect!</strong></p>');
  32. $error = true;
  33. }
  34. }
  35.  
  36. if (!$defaultDest)
  37. {
  38. $defaultDest = 'snatched';
  39. }
  40.  
  41. if (!file_exists($defaultDest))
  42. {
  43. mkdir($defaultDest);
  44. }
  45.  
  46. $sizelimit = $sizelimit * 1024;
  47.  
  48. $files = $_POST['file'];
  49. $news = $_POST['new'];
  50. $allfiles = $_POST['allfiles'];
  51. $separateby = $_POST['separateby'];
  52. if($allfiles != "")
  53. {
  54. $files = explode($separateby,$allfiles);
  55. }
  56. for($i=0;$i<count($files);$i++)
  57. {
  58.  
  59. $file = trim($files[$i]);
  60. $uploadfile = explode('/', $file);
  61. $filename = array_pop($uploadfile);
  62.  
  63. $newfilename = $news[$i];
  64.  
  65. if (!$newfilename)
  66. {
  67. $newfilename = $filename;
  68. }
  69.  
  70. if (!isset($file))
  71. {
  72. echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
  73. $error = true;
  74. }
  75.  
  76. if (!isset($newfilename))
  77. {
  78. echo '<p><strong>Please enter a new file name!</strong></p>';
  79. $error = true;
  80. }
  81.  
  82. if ($error == false)
  83. {
  84. $dest = $defaultDest;
  85. $ds = array($dest, '/', $newfilename);
  86. $ds = implode('', $ds);
  87. $newname_count = 0;
  88. if (file_exists($ds))
  89. {
  90. echo '<p><strong>File already exists!</strong></p>';
  91. $newname_count++;
  92. $newfile = array($newname_count, $newfilename);
  93. $newfile = implode('~', $newfile);
  94. $newfile_ds = array($dest, '/', $newfile);
  95. $newfile_ds = implode('', $newfile_ds);
  96. while($renamed == false)
  97. {
  98. if (file_exists($newfile_ds))
  99. {
  100. $newname_count++;
  101. $newfile = array($newname_count, $newfilename);
  102. $newfile = implode('~', $newfile);
  103. $newfile_ds = array($dest, '/', $newfile);
  104. $newfile_ds = implode('', $newfile_ds);
  105. }
  106. else
  107. {
  108. $renamed = true;
  109. }
  110. }
  111. $newfilename = $newfile;
  112. $ds = $newfile_ds;
  113. echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
  114. }
  115. echo '<p><strong>Copying...</strong></p>';
  116. if ($snatch_system == 'curl')
  117. {
  118. $ch = curl_init($file);
  119. $fp = fopen($ds, 'w');
  120. curl_setopt($ch, CURLOPT_FILE, $fp);
  121. curl_setopt($ch, CURLOPT_HEADER, 0);
  122. curl_exec($ch);
  123. $curl_info = curl_getinfo($ch);
  124. curl_close($ch);
  125. fclose($fp);
  126. }
  127. else
  128. {
  129. if (!copy($file, $ds))
  130. {
  131. echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
  132. $copy_fail = true;
  133. }
  134. }
  135.  
  136. if ($copy_fail == false)
  137. {
  138. if ($sizelimit > 0 && filesize($ds) > $sizelimit)
  139. {
  140. echo '<p><strong>File is too large.</strong>';
  141. unlink($ds);
  142. }
  143. else
  144. {
  145. echo '<p><strong>Copy successful!</strong></p>';
  146. echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
  147. if ($snatch_system == 'curl')
  148. {
  149. $size_dl = round($curl_info['size_download']/1024, 2);
  150. $speed_dl = round($curl_info['speed_download']/1024, 2);
  151. echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
  152. }
  153. }
  154. }
  155. }
  156.  
  157. }
  158. }
  159.  
  160. $self = $_SERVER['PHP_SELF'];
  161. ?>
  162.  
  163. <fieldset><legend>File Snatcher</legend>
  164. <label for="file">Full path to file to copy</label>
  165. <p>Example: http://foobar.com/image.png</p>
  166. <?
  167. $repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
  168. ?>
  169. <form method="POST" action="<?=$self?>">
  170. <input type="text" name="repeat" size="10" value="<?=$repeat;?>">
  171. <input name="Repeat" value="Repeat" type="submit">
  172. </form>
  173.  
  174. <form method="POST" action="<?=$self?>">
  175. <? for($i=0;$i<$repeat;$i++){?>
  176. <br>File<?=($i+1)?> : <input type="text" name="file[]" size="45" value="">
  177. <!--<input type="text" name="new[]" size="45" value="">-->
  178. <? } ?>
  179.  
  180. <label for="new">New file name (Optional)</label><br />
  181. <br>OR<br><br>
  182. <textarea name="allfiles" cols="100" rows="10">http://www.daniweb.com/rxrimages/feeds_rss.gif##http://www.daniweb.com/rxrimages/feeds_twitter.gif##http://www.daniweb.com/rxrimages/feeds_facebook.gif</textarea>
  183. Separate URL by:
  184. <input type="text" value="##" name="separateby" size="5" value="<?=$separateby;?>">
  185.  
  186. <p>Example: image.png</p>
  187.  
  188. <? if (isset($password)){ ?>
  189.  
  190. <label for="password">Password</label>
  191. <input type="password" name="password" id="password" size="45" value=""><br />
  192. <? } ?>
  193. <p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
  194. </form>
  195. </fieldset>
  196.  
  197. </div>
  198. </body>
  199. </html>
Reputation Points: 154
Solved Threads: 162
Master Poster
vibhadevit is offline Offline
791 posts
since Apr 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Auto refresh
Next Thread in PHP Forum Timeline: wrong sintax for alter table with compound foreign key





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC