Sixem

PHP Remote Download

Mar 9th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.54 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Remote Download</title>
  4. <script type="text/javascript">
  5. var i=12;
  6. var y=0;
  7. function AddMore(){
  8.     if (i<31){
  9.         var output = document.getElementById('content');
  10.         var ele = document.createElement("div");
  11.         ele.setAttribute("id","multidiv_" + i);
  12.         ele.innerHTML="URL: <input type=\"text\" id=\"multiid_url_" + i + "\" name=\"multi_" + i + "_URL\"> Save As: <input type=\"text\" id=\"multiid_" + i + "\" name=\"multi_file_" + i + "_filename\"><button type=\"button\" onclick=\"GrabFileName(\'multiid_" + i + "\');\">Strip Filename From URL</button>";
  13.         output.appendChild(ele);
  14.         i++;
  15.     }
  16.     if (i>30){
  17.         if (y==0){
  18.         var output = document.getElementById('content');
  19.         var ele = document.createElement("div");
  20.         ele.setAttribute("id","multidiv_error" + i);
  21.         ele.innerHTML="<h2>There\'s a limit of 30 downloads per request!</h2>";
  22.         output.appendChild(ele);
  23.         y=1;
  24.         }
  25.     }        
  26. }
  27. function GrabFileName($x){
  28.     var elem = document.getElementById($x);
  29.     var str = $x;
  30.     var doom = str.replace("multiid_","multiid_url_");
  31.     var file = document.getElementById(doom).value;
  32.     var strip = file.replace(/^.*[\\\/]/, '');
  33.     elem.value = strip;
  34. }
  35. </script>
  36. </head>
  37. <body>
  38. <?php
  39. function Yell($input){
  40.     return '<p>' . $input . '</p>';
  41. }
  42. ?>
  43. <?php
  44.  
  45.  
  46. if(isset($_POST['submit_multi'])) {
  47. $foldername = $_REQUEST['multi_0_folder'];
  48.  
  49.  
  50. if (file_exists($foldername)) {
  51. } else {
  52.     if(!empty($foldername) == TRUE){
  53.         if (!mkdir($foldername, 0777, true)) {
  54.             echo yell('Something went wrong when creating the folder, trying to continue..');
  55.         } else {
  56.             echo yell('Created folder: <a target="_blank" href="' . $foldername . '">' .  $foldername . '</a>, now storing files..');
  57.         }
  58.     }  
  59. }
  60.  
  61. $i = 1;
  62. while ($i <= 30){
  63.    
  64. if(!empty($_REQUEST['multi_' . $i . '_URL']) == TRUE){
  65.     if(!empty($_REQUEST['multi_file_' . $i . '_filename']) == TRUE){
  66.     $data_1 = file_get_contents($_REQUEST['multi_' . $i . '_URL']);
  67.     file_put_contents($foldername . '/' . $_REQUEST['multi_file_' . $i . '_filename'], $data_1);
  68.     $pathtoimage = str_replace('/', '', $foldername) . '/' . $_REQUEST['multi_file_' . $i . '_filename'];
  69.     echo Yell('Storing .. <a target="_blank" href="' . $pathtoimage . '">' . $_REQUEST['multi_file_' . $i . '_filename'] . '</a> .. OK!');
  70.     }
  71. }
  72.  
  73.     $i++;
  74. }
  75.  
  76. }
  77.  
  78.  
  79. if(isset($_REQUEST['submit_url'])) {
  80. $url = $_REQUEST['submit_url'];
  81. $data = file_get_contents($url);
  82. $path = pathinfo($url);
  83.  
  84. if(isset($path['extension'])){
  85. $extension = '.' . $path['extension'];
  86. $def = FALSE;
  87. } else {
  88. $extension = '.jpg';
  89. $def = TRUE;
  90. }
  91. $time_today = date('d-m-y_G-i-s', time());
  92. $fullname = 'temp_ignore/' . $time_today . $extension;
  93. file_put_contents($fullname, $data);
  94. echo '<p>Success!</p>';
  95. if($def == TRUE){
  96.     echo Yell('File extension could not be extracted from the path, file has been set to .jpg (default)');
  97. }
  98. echo Yell('File downloaded and stored in <a href="temp_ignore">temp_ignore</a> as <a href="temp_ignore/' . $time_today . $extension . '">' . $time_today . $extension . '</a>');
  99. echo Yell('Download it using FTP for the raw file</p>');
  100. }
  101. ?>
  102. <?php
  103. $isset = FALSE;
  104. $mode = 0;
  105. if(isset($_GET['mode'])) {
  106. $mode = $_GET['mode'];
  107. } else {
  108. $mode = 0;
  109. }
  110.  
  111. if($mode == 0){
  112. $isset = TRUE;
  113. echo '<form action="" method="POST" name="submit_download"><input type="text" name="submit_url"></input><input type="submit" value="OK"></input></form>';
  114. }
  115. if($mode == 1){
  116. $isset = TRUE;
  117. echo '<button type="button" onclick="AddMore();">Add Row +</button>';
  118. echo '<form action="" method="POST" name="multi_download" id="form_content"><div id="content">
  119. <div id="multidiv_0">New folder name: <input type="text" name="multi_0_folder"></div>
  120. <p>Include extensions on Save As part!</p>';
  121.  
  122. $i = 1;
  123. while ($i <= 11){
  124. echo '<div id="multidiv_' . $i . '">URL: <input type="text" id="multiid_url_' . $i . '" name="multi_' . $i . '_URL"> Save As: <input type="text" id="multiid_' . $i . '" name="multi_file_' . $i . '_filename"><button type="button" onclick="GrabFileName(\'multiid_' . $i . '\');">Strip Filename From URL</button></div>';
  125.     $i++;
  126. }
  127.  
  128. echo '</div><p>This may take some time depending on the file sizes!</p>
  129. <p></input><input type="submit" name="submit_multi" value="Store Files"></p></input>
  130. <p>';
  131. }
  132.  
  133. if($isset == FALSE){
  134. echo '<form action="" method="POST" name="submit_download"><input type="text" name="submit_url"></input><input type="submit" value="OK"></input></form>';
  135. }
  136. ?>
  137. <p>Use the mode call for different options, <a href="?mode=0">0</a> = default, <a href="?mode=1">1</a> = multiple downloads</p>
  138. </form>
  139. </body>
  140. </html>
Add Comment
Please, Sign In to add comment