Download script
Ik ben al sinds gisteren bezig met een download script.
Maar ik kom er niet echt uit waar hij controleerd welke bestand hij moet downloaden ik gebruik checkboxen om een bestandje aan te vinken die je wilt downloaden, maar ik weet niet hoe ik mijn script daar naar kan laten kijken.
Zou iemand mij mischien willen helpen?
alvast bedankt.
Dit script laat zien welke bestand je wilt downloaden.
Code (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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Naamloos document</title>
</head>
<body>
<p><a href="../index.html">Klik hier</a> om terug te gaan. </p><br />
<?
if (isset($_GET['klant']))
{
echo $_GET['klant'] . '<br>';
$targetDir = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "plupload";
$dir = $targetDir. DIRECTORY_SEPARATOR ."". $_GET['klant'];
if ($handle = @opendir($dir))
{
while (false !== ($file = @readdir($handle))) {
echo"<input type='checkbox' />";
echo "<a href='/plupload/'". $file ."' target='_blank'>". basename($file, ".php") ."</a><br>" ;
}
echo"<br><a style='padding: 5px; background-color: orange; border: 1px black solid; color: black; text-decoration: none;' href='downloader.php'>download</a>";
@closedir($handle);
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" value="" name="klant" />
<input type="submit" value="DO" />
</form>
<p>
<? } ?>
</p>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Naamloos document</title>
</head>
<body>
<p><a href="../index.html">Klik hier</a> om terug te gaan. </p><br />
<?
if (isset($_GET['klant']))
{
echo $_GET['klant'] . '<br>';
$targetDir = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "plupload";
$dir = $targetDir. DIRECTORY_SEPARATOR ."". $_GET['klant'];
if ($handle = @opendir($dir))
{
while (false !== ($file = @readdir($handle))) {
echo"<input type='checkbox' />";
echo "<a href='/plupload/'". $file ."' target='_blank'>". basename($file, ".php") ."</a><br>" ;
}
echo"<br><a style='padding: 5px; background-color: orange; border: 1px black solid; color: black; text-decoration: none;' href='downloader.php'>download</a>";
@closedir($handle);
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" value="" name="klant" />
<input type="submit" value="DO" />
</form>
<p>
<? } ?>
</p>
</body>
</html>
dit is de download script
Code (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
function force_download ($name)
{
global $config;
$extensie = get_extensions($name);
/**
* Bepalen bestandsgrootte
*/
$filesize = filesize($config['uploader'] . $name);
/**
* Bepalen juiste mimetype
*/
$mimetype = set_mimetype($extensie);
/**
* Al de verdere output leegmaken
*/
ob_clean_all();
/**
* Verzenden headers
*/
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename=\"" . $name . "\";" );
readfile($config['uploader'] . $name);
//Send data
//echo $data;
die();
}
function ob_clean_all ()
{
$ob_active = ob_get_length () !== false;
while($ob_active)
{
ob_end_clean();
$ob_active = ob_get_length () !== false;
}
return true;
}
/**
* Bepalen extensie van een file
*/
function get_extensions($filenaam)
{
$filenaam_array = explode(".", $filenaam);
$filenaam_aantal = count($filenaam_array);
$extensie = $filenaam_array[$filenaam_aantal-1];
return $extensie;
}
/**
* Ophalen juiste mime-types
*/
function set_mimetype($extensie)
{
$mimetype_array = array(
'application/andrew-inset' => 'ez',
'application/mac-binhex40' => 'hqx',
'application/mac-compactpro' => 'cpt',
'application/mathml+xml' => 'mathml',
'application/msword' => 'doc',
'application/octet-stream' => 'bin',
'application/octet-stream' => 'dms',
'application/octet-stream' => 'lha',
'application/octet-stream' => 'lzh',
'application/octet-stream' => 'exe',
'application/octet-stream' => 'dll',
'application/octet-stream' => 'dmg',
'application/oda' => 'oda',
'application/ogg' => 'ogg',
'application/pdf' => 'pdf',
'application/postscript' => 'ai',
'application/postscript' => 'eps',
'application/postscript' => 'ps',
'application/rdf+xml' => 'rdf',
'application/smil' => 'smi',
'application/smil' => 'smil',
'application/srgs' => 'gram',
'application/srgs+xml' => 'grxml',
'application/vnd.mif' => 'mif',
'application/vnd.mozilla.xul+xml' => 'xul',
'application/vnd.ms-excel' => 'xls',
'application/vnd.ms-powerpoint' => 'ppt',
'application/vnd.wap.wbxml' => 'wbxml',
'application/vnd.wap.wmlc' => '.wmlc',
'application/vnd.wap.wmlc' => 'wmlc',
'application/vnd.wap.wmlscriptc' => 'wmlsc',
'application/voicexml+xml' => 'vxml',
'application/x-bcpio' => 'bcpio',
'application/x-cdlink' => 'vcd',
'application/x-chess-pgn' => 'pgn',
'application/x-cpio' => 'cpio',
'application/x-csh' => 'csh',
'application/x-director' => 'dcr',
'application/x-director' => 'dir',
'application/x-director' => 'dxr',
'application/x-dvi' => 'dvi',
'application/x-futuresplash' => 'spl',
'application/x-gtar' => 'gtar',
'application/x-hdf' => 'hdf',
'application/x-httpd-php' => 'php',
'application/x-httpd-php' => 'php4',
'application/x-httpd-php' => 'php3',
'application/x-httpd-php' => 'phtml',
'application/x-httpd-php-source' => 'phps',
'application/x-javascript' => 'js',
'application/x-koan' => 'skp',
'application/x-koan' => 'skd',
'application/x-koan' => 'skt',
'application/x-koan' => 'skm',
'application/x-latex' => 'latex',
'application/x-netcdf' => 'nc',
'application/x-netcdf' => 'cdf',
'application/x-pkcs7-crl' => '.crl',
'application/x-sh' => 'sh',
'application/x-shar' => 'shar',
'application/x-shockwave-flash' => 'swf',
'application/x-stuffit' => 'sit',
'application/x-sv4cpio' => 'sv4cpio',
'application/x-sv4crc' => 'sv4crc',
'application/x-tar' => '.tgz',
'application/x-tar' => 'tar',
'application/x-tcl' => 'tcl',
'application/x-tex' => 'tex',
'application/x-texinfo' => 'texinfo',
'application/x-texinfo' => 'texi',
'application/x-troff' => 't',
'application/x-troff' => 'tr',
'application/x-troff' => 'roff',
'application/x-troff-man' => 'man',
'application/x-troff-me' => 'me',
'application/x-troff-ms' => 'ms',
'application/x-ustar' => 'ustar',
'application/x-wais-source' => 'src',
'application/x-x509-ca-cert' => '.crt',
'application/xhtml+xml' => 'xhtml',
'application/xhtml+xml' => 'xht',
'application/xml' => 'xml',
'application/xml' => 'xsl',
'application/xml-dtd' => 'dtd',
'application/xslt+xml' => 'xslt',
'application/zip' => 'zip',
'audio/basic' => 'au',
'audio/basic' => 'snd',
'audio/midi' => 'mid',
'audio/midi' => 'midi',
'audio/midi' => 'kar',
'audio/mpeg' => 'mpga',
'audio/mpeg' => 'mp2',
'audio/mpeg' => 'mp3',
'audio/x-aiff' => 'aif',
'audio/x-aiff' => 'aiff',
'audio/x-aiff' => 'aifc',
'audio/x-mpegurl' => 'm3u',
'audio/x-pn-realaudio' => 'ram',
'audio/x-pn-realaudio' => 'rm',
'audio/x-pn-realaudio-plugin' => 'rpm',
'audio/x-realaudio' => 'ra',
'audio/x-wav' => 'wav',
'chemical/x-pdb' => 'pdb',
'chemical/x-xyz' => 'xyz',
'image/bmp' => 'bmp',
'image/cgm' => 'cgm',
'image/gif' => 'gif',
'image/ief' => 'ief',
'image/jpeg' => 'jpeg',
'image/jpeg' => 'jpg',
'image/jpeg' => 'jpe',
'image/png' => 'png',
'image/svg+xml' => 'svg',
'image/tiff' => 'tiff',
'image/tiff' => 'tif',
'image/vnd.djvu' => 'djvu',
'image/vnd.djvu' => 'djv',
'image/vnd.wap.wbmp' => 'wbmp',
'image/x-cmu-raster' => 'ras',
'image/x-icon' => 'ico',
'image/x-portable-anymap' => 'pnm',
'image/x-portable-bitmap' => 'pbm',
'image/x-portable-graymap' => 'pgm',
'image/x-portable-pixmap' => 'ppm',
'image/x-rgb' => 'rgb',
'image/x-xbitmap' => 'xbm',
'image/x-xpixmap' => 'xpm',
'image/x-xwindowdump' => 'xwd',
'model/iges' => 'igs',
'model/iges' => 'iges',
'model/mesh' => 'msh',
'model/iges' => 'iges',
'model/mesh' => 'mesh',
'model/iges' => 'iges',
'model/mesh' => 'silo',
'model/vrml' => 'wrl',
'model/vrml' => 'vrml',
'text/calendar' => 'ics',
'text/calendar' => 'ifb',
'text/css' => 'css',
'text/html' => 'shtml',
'text/html' => 'html',
'text/html' => 'htm',
'text/plain' => 'asc',
'text/plain' => 'txt',
'text/richtext' => 'rtx',
'text/rtf' => 'rtf',
'text/sgml' => 'sgml',
'text/sgml' => 'sgm',
'text/tab-separated-values' => 'tsv',
'text/vnd.wap.wml' => '.wml',
'text/vnd.wap.wml' => 'wml',
'text/vnd.wap.wmlscript' => 'wmls',
'text/vnd.wap.wmlscript' => 'wmls',
'text/x-setext' => 'etx',
'video/mpeg' => 'mpeg',
'video/mpeg' => 'mpg',
'video/mpeg' => 'mpeg',
'video/mpeg' => 'mpe',
'video/quicktime' => 'qt',
'video/quicktime' => 'mov',
'video/vnd.mpegurl' => 'mxu',
'video/vnd.mpegurl' => 'm4u',
'video/x-msvideo' => 'avi',
'video/x-sgi-movie' => 'movie'
);
while ($mimetype_extensie = current($mimetype_array))
{
if ($mimetype_extensie == $extensie) {
echo key($mimetype_array).'<br />';
$mimetype = key($mimetype_array);
}
next($mimetype_array);
}
}
/**
* Bepalen naam file
*/
$name = $item['upload_naam'];
//echo $extensie;
force_download ($name);
?>
function force_download ($name)
{
global $config;
$extensie = get_extensions($name);
/**
* Bepalen bestandsgrootte
*/
$filesize = filesize($config['uploader'] . $name);
/**
* Bepalen juiste mimetype
*/
$mimetype = set_mimetype($extensie);
/**
* Al de verdere output leegmaken
*/
ob_clean_all();
/**
* Verzenden headers
*/
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename=\"" . $name . "\";" );
readfile($config['uploader'] . $name);
//Send data
//echo $data;
die();
}
function ob_clean_all ()
{
$ob_active = ob_get_length () !== false;
while($ob_active)
{
ob_end_clean();
$ob_active = ob_get_length () !== false;
}
return true;
}
/**
* Bepalen extensie van een file
*/
function get_extensions($filenaam)
{
$filenaam_array = explode(".", $filenaam);
$filenaam_aantal = count($filenaam_array);
$extensie = $filenaam_array[$filenaam_aantal-1];
return $extensie;
}
/**
* Ophalen juiste mime-types
*/
function set_mimetype($extensie)
{
$mimetype_array = array(
'application/andrew-inset' => 'ez',
'application/mac-binhex40' => 'hqx',
'application/mac-compactpro' => 'cpt',
'application/mathml+xml' => 'mathml',
'application/msword' => 'doc',
'application/octet-stream' => 'bin',
'application/octet-stream' => 'dms',
'application/octet-stream' => 'lha',
'application/octet-stream' => 'lzh',
'application/octet-stream' => 'exe',
'application/octet-stream' => 'dll',
'application/octet-stream' => 'dmg',
'application/oda' => 'oda',
'application/ogg' => 'ogg',
'application/pdf' => 'pdf',
'application/postscript' => 'ai',
'application/postscript' => 'eps',
'application/postscript' => 'ps',
'application/rdf+xml' => 'rdf',
'application/smil' => 'smi',
'application/smil' => 'smil',
'application/srgs' => 'gram',
'application/srgs+xml' => 'grxml',
'application/vnd.mif' => 'mif',
'application/vnd.mozilla.xul+xml' => 'xul',
'application/vnd.ms-excel' => 'xls',
'application/vnd.ms-powerpoint' => 'ppt',
'application/vnd.wap.wbxml' => 'wbxml',
'application/vnd.wap.wmlc' => '.wmlc',
'application/vnd.wap.wmlc' => 'wmlc',
'application/vnd.wap.wmlscriptc' => 'wmlsc',
'application/voicexml+xml' => 'vxml',
'application/x-bcpio' => 'bcpio',
'application/x-cdlink' => 'vcd',
'application/x-chess-pgn' => 'pgn',
'application/x-cpio' => 'cpio',
'application/x-csh' => 'csh',
'application/x-director' => 'dcr',
'application/x-director' => 'dir',
'application/x-director' => 'dxr',
'application/x-dvi' => 'dvi',
'application/x-futuresplash' => 'spl',
'application/x-gtar' => 'gtar',
'application/x-hdf' => 'hdf',
'application/x-httpd-php' => 'php',
'application/x-httpd-php' => 'php4',
'application/x-httpd-php' => 'php3',
'application/x-httpd-php' => 'phtml',
'application/x-httpd-php-source' => 'phps',
'application/x-javascript' => 'js',
'application/x-koan' => 'skp',
'application/x-koan' => 'skd',
'application/x-koan' => 'skt',
'application/x-koan' => 'skm',
'application/x-latex' => 'latex',
'application/x-netcdf' => 'nc',
'application/x-netcdf' => 'cdf',
'application/x-pkcs7-crl' => '.crl',
'application/x-sh' => 'sh',
'application/x-shar' => 'shar',
'application/x-shockwave-flash' => 'swf',
'application/x-stuffit' => 'sit',
'application/x-sv4cpio' => 'sv4cpio',
'application/x-sv4crc' => 'sv4crc',
'application/x-tar' => '.tgz',
'application/x-tar' => 'tar',
'application/x-tcl' => 'tcl',
'application/x-tex' => 'tex',
'application/x-texinfo' => 'texinfo',
'application/x-texinfo' => 'texi',
'application/x-troff' => 't',
'application/x-troff' => 'tr',
'application/x-troff' => 'roff',
'application/x-troff-man' => 'man',
'application/x-troff-me' => 'me',
'application/x-troff-ms' => 'ms',
'application/x-ustar' => 'ustar',
'application/x-wais-source' => 'src',
'application/x-x509-ca-cert' => '.crt',
'application/xhtml+xml' => 'xhtml',
'application/xhtml+xml' => 'xht',
'application/xml' => 'xml',
'application/xml' => 'xsl',
'application/xml-dtd' => 'dtd',
'application/xslt+xml' => 'xslt',
'application/zip' => 'zip',
'audio/basic' => 'au',
'audio/basic' => 'snd',
'audio/midi' => 'mid',
'audio/midi' => 'midi',
'audio/midi' => 'kar',
'audio/mpeg' => 'mpga',
'audio/mpeg' => 'mp2',
'audio/mpeg' => 'mp3',
'audio/x-aiff' => 'aif',
'audio/x-aiff' => 'aiff',
'audio/x-aiff' => 'aifc',
'audio/x-mpegurl' => 'm3u',
'audio/x-pn-realaudio' => 'ram',
'audio/x-pn-realaudio' => 'rm',
'audio/x-pn-realaudio-plugin' => 'rpm',
'audio/x-realaudio' => 'ra',
'audio/x-wav' => 'wav',
'chemical/x-pdb' => 'pdb',
'chemical/x-xyz' => 'xyz',
'image/bmp' => 'bmp',
'image/cgm' => 'cgm',
'image/gif' => 'gif',
'image/ief' => 'ief',
'image/jpeg' => 'jpeg',
'image/jpeg' => 'jpg',
'image/jpeg' => 'jpe',
'image/png' => 'png',
'image/svg+xml' => 'svg',
'image/tiff' => 'tiff',
'image/tiff' => 'tif',
'image/vnd.djvu' => 'djvu',
'image/vnd.djvu' => 'djv',
'image/vnd.wap.wbmp' => 'wbmp',
'image/x-cmu-raster' => 'ras',
'image/x-icon' => 'ico',
'image/x-portable-anymap' => 'pnm',
'image/x-portable-bitmap' => 'pbm',
'image/x-portable-graymap' => 'pgm',
'image/x-portable-pixmap' => 'ppm',
'image/x-rgb' => 'rgb',
'image/x-xbitmap' => 'xbm',
'image/x-xpixmap' => 'xpm',
'image/x-xwindowdump' => 'xwd',
'model/iges' => 'igs',
'model/iges' => 'iges',
'model/mesh' => 'msh',
'model/iges' => 'iges',
'model/mesh' => 'mesh',
'model/iges' => 'iges',
'model/mesh' => 'silo',
'model/vrml' => 'wrl',
'model/vrml' => 'vrml',
'text/calendar' => 'ics',
'text/calendar' => 'ifb',
'text/css' => 'css',
'text/html' => 'shtml',
'text/html' => 'html',
'text/html' => 'htm',
'text/plain' => 'asc',
'text/plain' => 'txt',
'text/richtext' => 'rtx',
'text/rtf' => 'rtf',
'text/sgml' => 'sgml',
'text/sgml' => 'sgm',
'text/tab-separated-values' => 'tsv',
'text/vnd.wap.wml' => '.wml',
'text/vnd.wap.wml' => 'wml',
'text/vnd.wap.wmlscript' => 'wmls',
'text/vnd.wap.wmlscript' => 'wmls',
'text/x-setext' => 'etx',
'video/mpeg' => 'mpeg',
'video/mpeg' => 'mpg',
'video/mpeg' => 'mpeg',
'video/mpeg' => 'mpe',
'video/quicktime' => 'qt',
'video/quicktime' => 'mov',
'video/vnd.mpegurl' => 'mxu',
'video/vnd.mpegurl' => 'm4u',
'video/x-msvideo' => 'avi',
'video/x-sgi-movie' => 'movie'
);
while ($mimetype_extensie = current($mimetype_array))
{
if ($mimetype_extensie == $extensie) {
echo key($mimetype_array).'<br />';
$mimetype = key($mimetype_array);
}
next($mimetype_array);
}
}
/**
* Bepalen naam file
*/
$name = $item['upload_naam'];
//echo $extensie;
force_download ($name);
?>
Meschien zit daar je probleem
en op me readfile($config['uploader'] . $name); uploader heb ik nu trouwens veranderd naar file maar hij wilt nog steeds niet werken.
heb je meschien een linkje waar ik naar kan kijken
nawienkantine.iteeuwen.nl
Kortom, zorg dat je het formulier waarin je downloads kunt selecteren, goed opbouwt. Verzend dat formulier vervolgens en gebruik dan de functie force_download() om de bestanden als download aan te bieden.
Blanche - op 15/02/2011 12:45:00:
Je genereert in je eerste scriptje wel een leuk lijstje met checkboxen, maar die zijn helemaal geen onderdeel van een formulier. En die 'download' link doet niets meer dan de gebruiker doorsturen naar download.php, zonder ook maar enige verdere informatie mee te geven.
Kortom, zorg dat je het formulier waarin je downloads kunt selecteren, goed opbouwt. Verzend dat formulier vervolgens en gebruik dan de functie force_download() om de bestanden als download aan te bieden.
Kortom, zorg dat je het formulier waarin je downloads kunt selecteren, goed opbouwt. Verzend dat formulier vervolgens en gebruik dan de functie force_download() om de bestanden als download aan te bieden.
oke dankjewel ik zal het proberen
Toevoeging op 15/02/2011 14:52:26:
ik heb het nou zo ver gekregen dat hij het bestand uitleest die je aangevinkt hebt maar ik weet niet hoe ik ervoor kan zorgen dat hij download