mp3 in download script
Ik gebruik dit script: http://www.phphulp.nl/php/scripts/7/244/
code:
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
if ($fd = fopen ($fullPath, "r")) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
if ($fd = fopen ($fullPath, "r")) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
waarom krijg ik deze error:
Warning: fopen(http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\server\Apache2\htdocs\download.php on line 24
Warning: fclose(): supplied argument is not a valid stream resource in C:\server\Apache2\htdocs\download.php on line 42
Je kan geen externe files openen of het bestand bestaat niet.
http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3
maar hij denkt dus dat ie niet bestaat :s hoe kan dat ?
EDIT: ik draai op localhost, is dat het ?
Gewijzigd op 01/01/1970 01:00:00 door nicky van boven
Moet er misschien een content type in het script speciaal voor mp3's ?
of ligt dat aan mij?? :P
Waarschijnlijk staan je fopen wrappers niet aan en kun je geen URLs invoeren. Je moet dus het lokale path opgeven en niet HTTP.
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
hij moet het dan doen toch ?
Twan:
ik kan die link niet openen :S
of ligt dat aan mij?? :P
of ligt dat aan mij?? :P
Dat ligt aan je pc..
lol echt een PHP-raadsel :p
Wat krijg je nu?
Als het fouten zijn, los die op als dat wel werkt gebruik dit dan ipv fopen
Gewijzigd op 01/01/1970 01:00:00 door Han eev
het werkt o.0 er word gevraagd of ik download.php wil downloaden en als ik het rename naar download.mp3 werkt het ! :-O
ik probeerde filegetcontents in het script te implementeren, en toen deed ie het wel maar toen downloade die een bestand van 88,9 mb (geen idee waarvandaan) met de naam van het bestand. Toen ik het probeerde af te spelen op mn desktop gaf die de melding dat de extensie niet met de bestandsindeling overeen kwam.
Dit is het script:
// download.php
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
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
<?php
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
if (file_get_contents($fullPath)) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
exit;
?>
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
if (file_get_contents($fullPath)) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
exit;
?>
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
$file = file_get_contents($fullPath);
if ($file) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
echo $file;
}
exit;
?>
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
$file = file_get_contents($fullPath);
if ($file) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Cache-control: private"); //use this to open files directly
echo $file;
}
exit;
?>
Nu werkt het als het goed is.
Han:
Nu werkt het als het goed is.
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
$file = file_get_contents($fullPath);
if ($file) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename="".$path_parts["basename"]."""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename="".$path_parts["basename"]."""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename="".$path_parts["basename"].""");
}
header("Cache-control: private"); //use this to open files directly
echo $file;
}
exit;
?>
$fullPath ="http://www.madpaintball.co.uk/userfiles/punjabi_lose_yourself.mp3";
$file = file_get_contents($fullPath);
if ($file) {
$path_parts = pathinfo($fullPath); //ver 1.02 uses pathinfo now
$ext = strtolower($path_parts["extension"]); //ver 1.01: Added the stringconv. to handle also extensions with caps
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename="".$path_parts["basename"]."""); // use 'attachement' to force a download
break;
case "mp3":
header("Content-Type: plain/text"); // add here more headers for diff. extensions
header("Content-Disposition: filename="".$path_parts["basename"]."""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename="".$path_parts["basename"].""");
}
header("Cache-control: private"); //use this to open files directly
echo $file;
}
exit;
?>
Nu werkt het als het goed is.
omg jij bent goed Han ! (Y)