Toon posts:

[php] bestanden dowloaden naar m'n server (van url)

Pagina: 1
Acties:
  • 53 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik draai nu een php webserver en ik heb nu een upload mogelijkheid (zodat mensen bestanden op m'n server kunnen plaatsen)
maar graag zou ik ook bestanden op m'n server kunnen downloaden rechtstreeks van een url (bvb http://www.download.com/files/installwinzip.exe)
Heeft hier iemand tips voor?

tnx

  • André
  • Registratie: Maart 2002
  • Laatst online: 11-05 16:42

André

Analytics dude

Ja, met een serverside script op de server kun je die bestanden wel downloaden naar die server. Wat zeiden de zoekresultaten?

/edit:
* André zal eens voor je zoeken:
[rml][ PHP] Hoe download ik een bestand?[/rml]

[ Voor 29% gewijzigd door André op 01-02-2005 01:12 ]


  • Room42
  • Registratie: September 2001
  • Niet online
Die functionaliteit heb ik mijn eigen filemanager ook gegeven! Superhandig, als je bijvoorbeeld op het werk niet kan downloaden van een bepaalde site :D

Dit is wat ik heb, doe ermee wat je wilt.
Het is wat oude code dus wellicht dat ik het beter kan :) Tipz zijn altijd welkom ;)

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function processdownload() {
  // Processes the URL-download

  global $storepath, $DB_site;
  $url=$_POST[geturl];

  /*/ Display message before downloading
  echo '<td class="upload"><p class="error"><br /><br />Attempting to download from:<br />'.$url.'<br /></p></td>';
  flush;*/

  // Delete other temp files
  cleanup();

  // Download requested file(s)
  $execcmd='wget -nv -T30 -t3 --passive-ftp --directory-prefix=\''.$storepath.'dltemp\' '.escapeshellarg($url);
  exec($execcmd);

  // Generate filelist for users acknowledgement
  $files='';
  $i=0;
  $downloads=dir($storepath.'dltemp');
  while (false !== ($entry = $downloads->read())) {
    if ($entry!="." and $entry!="..") {
          $i++;
          $file['name'][$i]=$entry;
          $file['size'][$i]=filesize($storepath.'dltemp/'.$entry);

      $files.="<strong>{$file['name'][$i]}</strong> (".(intval(($file['size'][$i]/1024)*100)/100)." kB)<br />";
        }
  }
  $downloads->close();

  // Download success, but does they need to be saved?
  include('./header.inc.php');
  if ($i>=1) {
        $return ='<strong>Successfully downloaded this file(s):</strong><br />'.$files.'<br /><br /><strong>Do you want to save this download(s)?</strong>';
        $return.='<form name="storeform" id="storeform" action="'.$_SERVER[PHP_SELF].'" method="POST"><input type="hidden" name="action" value="savefiles">';
        $return.='<p class="strong"><a href="javascript:void()" onclick="document.storeform.submit();">[ Yes ]</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?action=cleanup">[ No ]</a><br /><br /></p></form>';
        echo '<td class="upload"><p class="strong"><br /><br />'.$return.'<br /></p></td>';
  } else {
        $return ='Error: Download failed; no files saved!';
    echo '<td class="upload"><p class="error"><br /><br />'.$return.'<br /></p></td>';
  }
  include('./footer.inc.php');
  exit;
}

function storedownload() {
  // Store the downloaded files into the database

  global $storepath, $DB_site;

  $files='';
  $i=0;
  $downloads=dir($storepath.'dltemp');
  while (false !== ($entry = $downloads->read())) {
    if ($entry!="." and $entry!="..") {
          $fileid=getfileid();
          $source=$storepath.'dltemp/'.$entry;
          $target=$storepath."stor".$fileid;

          // Get info for database
          $filename=$entry;
          $filesize=filesize($source);
          $comments=addslashes($_POST[comments]);

          // Move from download dir to storage dir
          rename($source,$target);

          // All fine, add database entry
          $DB_site->query("INSERT INTO filenames (id,filename,size,fileid,dateline,comments)
                           VALUES ('0','".$filename."','".$filesize."','".$fileid."','".time()."','".$comments."')");
        }
  }
  $downloads->close();

  message('File(s) successfully stored!',"strong","?");
  exit;
}

function cleanup() {
  // Deletes all files in /dltemp under $storepath

  global $storepath;

  $oldtemps=dir($storepath.'dltemp');
  while (false !== ($entry = $oldtemps->read())) {
        if ($entry!="." and $entry!="..") {
          unlink($storepath.'dltemp/'.$entry);
        }
  }
  $oldtemps->close();
}


Korte uitleg algemene werking van mijn Filemanager: Bestanden worden in $storepath opgeslagen met een random ID. De echte filename wordt in de database opgeslagen.

[ Voor 174% gewijzigd door Room42 op 01-02-2005 01:22 ]

Koop al mijn ads!


  • Willem
  • Registratie: Februari 2001
  • Laatst online: 15-05 23:38
Doe zelf ook eens een keer wat moeite om wat uit te zoeken / anderen te helpen :/

Motor (of auto) onderhoud bijhouden


Dit topic is gesloten.