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 /*settings.php*/ <?php defined('_ALLOWINCLUDE') or die(); // Default destination to copy files too NO TRAILING SLASH!! // If it is complete path, file be copied there ex: /home/public_html/FOLDER (Linux), C:\htdocs\FOLDER (Windows) // If it is just a direcotory it will be copied to that directory in directory the script is in ex: /SnatcherFolder/FOLDER $defaultDest = 'snatched'; /* More examples If $defaultDest = ''; it will automatically copy to the `snatched` directory inside of the script's directory. If $defaultDest = 'files'; it will copy to `files` directory inside of the script's directory. */ // If you want a password to be required // Remember if you don't have a password anyone can copy a file to your server! $password = ''; // URL to location of snatched files WITH OUT TRAILING SLASH $URLDest = 'http://example.com/snatched'; // Put a limit for file size in kilobytes (1024KB is 1MB) // For unlimited put 0 // Example $sizelimit = 25; $sizelimit = 0; ?> PHP: index.php <?php //File Snatcher 2.7 define('_ALLOWINCLUDE',0); include 'settings.php'; $version = '2.7'; ////////////////////////////////////////////// //Do Not Change Below Here//////////////////// ////////////////////////////////////////////// if (function_exists('curl_init')) { $snatch_system = 'curl'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <title>File Snatcher <?php echo $version; ?> - © http://noveis.net</title> </head> <body> <div id="main"> <?php $submit = $_POST['submit']; if ($submit) { if (isset($password)) { if ($_POST['password'] != $password) { die('<p><strong>Password incorrect!</strong></p>'); $error = true; } } if (!$defaultDest) { $defaultDest = 'snatched'; } if (!file_exists($defaultDest)) { mkdir($defaultDest); } $sizelimit = $sizelimit * 1024; $file = $_POST['file']; $uploadfile = explode('/', $file); $filename = array_pop($uploadfile); $newfilename = $_POST['new']; if (!$newfilename) { $newfilename = $filename; } if (!isset($file)) { echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>'; $error = true; } if (!isset($newfilename)) { echo '<p><strong>Please enter a new file name!</strong></p>'; $error = true; } if ($error == false) { $dest = $defaultDest; $ds = array($dest, '/', $newfilename); $ds = implode('', $ds); $newname_count = 0; if (file_exists($ds)) { echo '<p><strong>File already exists!</strong></p>'; $newname_count++; $newfile = array($newname_count, $newfilename); $newfile = implode('~', $newfile); $newfile_ds = array($dest, '/', $newfile); $newfile_ds = implode('', $newfile_ds); while($renamed == false) { if (file_exists($newfile_ds)) { $newname_count++; $newfile = array($newname_count, $newfilename); $newfile = implode('~', $newfile); $newfile_ds = array($dest, '/', $newfile); $newfile_ds = implode('', $newfile_ds); } else { $renamed = true; } } $newfilename = $newfile; $ds = $newfile_ds; echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>'; } echo '<p><strong>Copying...</strong></p>'; if ($snatch_system == 'curl') { $ch = curl_init($file); $fp = fopen($ds, 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); $curl_info = curl_getinfo($ch); curl_close($ch); fclose($fp); } else { if (!copy($file, $ds)) { echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>'; $copy_fail = true; } } if ($copy_fail == false) { if ($sizelimit > 0 && filesize($ds) > $sizelimit) { echo '<p><strong>File is too large.</strong>'; unlink($ds); } else { echo '<p><strong>Copy successful!</strong></p>'; echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>'; if ($snatch_system == 'curl') { $size_dl = round($curl_info['size_download']/1024, 2); $speed_dl = round($curl_info['speed_download']/1024, 2); echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.'; } } } } } $self = $_SERVER['PHP_SELF']; echo '<form method="POST" action="'.$self.'">'; echo '<fieldset><legend>File Snatcher</legend>'; echo '<label for="file">Full path to file to copy</label>'; echo '<p>Example: http://foobar.com/image.png</p>'; echo '<input type="text" name="file" id="file" size="45" value="">'; echo '<label for="new">New file name (Optional)</label><br />'; echo '<p>Example: image.png</p>'; echo '<input type="text" name="new" id="new" size="45" value="">'; if (isset($password)) { echo '<label for="password">Password</label>'; echo '<input type="password" name="password" id="password" size="45" value=""><br />'; } echo '<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>'; echo '</fieldset></form>'; ?> </div> </body> </html> PHP: Please help me guys. Thanks in advance
You need to change a lot of these veriables into arrays to hold more information (each file you want sent), then use a for each loop to send each one. If you want it to send more than one at a time. your going to have to do A LOT more work, namly, change the way your doing the whole thing. lol Try looking up FTP with PHP. it would save you a ton of time.
<input type="text" name="file" id="file" size="45" value=""> Wouldn't that need to be type "file" instead of type "text"? Also to have multiple files, you would need array names. <input type="file" name="file[]" id="file" size="45" value=""> <input type="file" name="file[]" id="file" size="45" value=""> Having two of these will produce a $_POST['file'][] array. coz if you want more, you will need more fields. You can dynamically allocate them using dom method cloneNode().