General Upload Script


SUBMITTED BY: Guest

DATE: Sept. 26, 2014, 10:02 a.m.

FORMAT: PHP

SIZE: 1.2 kB

HITS: 1379

  1. <?php
  2. // UPLOAD.PHP
  3. if($_POST["submit"]){
  4. $url = trim($_POST["url"]);
  5. if($url){
  6. $file = fopen($url,"rb");
  7. if($file){
  8. $directory = "./downloads/"; // Directory to upload files to.
  9. $valid_exts = array("jpg","jpeg","gif","png","zip"); // default image only extensions
  10. $ext = end(explode(".",strtolower(basename($url))));
  11. if(in_array($ext,$valid_exts)){
  12. $rand = rand(1000,9999);
  13. $filename = $rand . basename($url);
  14. $newfile = fopen($directory . $filename, "wb"); // creating new file on local server
  15. if($newfile){
  16. while(!feof($file)){
  17. // Write the url file to the directory.
  18. fwrite($newfile,fread($file,1024 * 8),1024 * 8); // write the file to the new directory at a rate of 8kb/sec. until we reach the end.
  19. }
  20. echo 'File uploaded successfully! You can access the file here:'."\n";
  21. echo ''.$directory.$filename.'';
  22. } else { echo 'Could not establish new file ('.$directory.$filename.') on local server. Be sure to CHMOD your directory to 777.'; }
  23. } else { echo 'Invalid file type. Please try another file.'; }
  24. } else { echo 'Could not locate the file: '.$url.''; }
  25. } else { echo 'Invalid URL entered. Please try again.'; }
  26. }
  27. ?>

comments powered by Disqus