Downloading MP3 and MP4 files using PHP
up vote
0
down vote
favorite
I am making a downloader for mp3 and mp4 and i want two php files in php with 2 buttons calling both php files but only the first php file works.
code for popup.php
<?php
include "downloadmp3.php";
include "downloadmp4.php";
?>
<html>
<head></head>
<body bgcolor="#E6E6E6">
<form method="post">
<label for="url">Download mp3:</label>
<input type="text" name="url" value="" id="url">
<input type="submit" name="submit" value="Download">
<hr>
</form>
<form method="post">
<label for="url1">Download mp4:</label>
<input type="text" name="url1" value="" id="url1">
<input type="submit" name="submit" value="Download">
</form>
</body>
</html>
code for downloadmp3.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url']) && !empty($_POST['url'])) ? $_POST['url'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
and code for downloadmp4.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url1']) && !empty($_POST['url1'])) ? $_POST['url1'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url1=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
Updated:
Form submitted for MP3 form works.
But form submitted for MP4 doesn't works.
Please provide an solution to make it work.
php html download include mp3
add a comment |
up vote
0
down vote
favorite
I am making a downloader for mp3 and mp4 and i want two php files in php with 2 buttons calling both php files but only the first php file works.
code for popup.php
<?php
include "downloadmp3.php";
include "downloadmp4.php";
?>
<html>
<head></head>
<body bgcolor="#E6E6E6">
<form method="post">
<label for="url">Download mp3:</label>
<input type="text" name="url" value="" id="url">
<input type="submit" name="submit" value="Download">
<hr>
</form>
<form method="post">
<label for="url1">Download mp4:</label>
<input type="text" name="url1" value="" id="url1">
<input type="submit" name="submit" value="Download">
</form>
</body>
</html>
code for downloadmp3.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url']) && !empty($_POST['url'])) ? $_POST['url'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
and code for downloadmp4.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url1']) && !empty($_POST['url1'])) ? $_POST['url1'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url1=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
Updated:
Form submitted for MP3 form works.
But form submitted for MP4 doesn't works.
Please provide an solution to make it work.
php html download include mp3
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am making a downloader for mp3 and mp4 and i want two php files in php with 2 buttons calling both php files but only the first php file works.
code for popup.php
<?php
include "downloadmp3.php";
include "downloadmp4.php";
?>
<html>
<head></head>
<body bgcolor="#E6E6E6">
<form method="post">
<label for="url">Download mp3:</label>
<input type="text" name="url" value="" id="url">
<input type="submit" name="submit" value="Download">
<hr>
</form>
<form method="post">
<label for="url1">Download mp4:</label>
<input type="text" name="url1" value="" id="url1">
<input type="submit" name="submit" value="Download">
</form>
</body>
</html>
code for downloadmp3.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url']) && !empty($_POST['url'])) ? $_POST['url'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
and code for downloadmp4.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url1']) && !empty($_POST['url1'])) ? $_POST['url1'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url1=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
Updated:
Form submitted for MP3 form works.
But form submitted for MP4 doesn't works.
Please provide an solution to make it work.
php html download include mp3
I am making a downloader for mp3 and mp4 and i want two php files in php with 2 buttons calling both php files but only the first php file works.
code for popup.php
<?php
include "downloadmp3.php";
include "downloadmp4.php";
?>
<html>
<head></head>
<body bgcolor="#E6E6E6">
<form method="post">
<label for="url">Download mp3:</label>
<input type="text" name="url" value="" id="url">
<input type="submit" name="submit" value="Download">
<hr>
</form>
<form method="post">
<label for="url1">Download mp4:</label>
<input type="text" name="url1" value="" id="url1">
<input type="submit" name="submit" value="Download">
</form>
</body>
</html>
code for downloadmp3.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url']) && !empty($_POST['url'])) ? $_POST['url'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
and code for downloadmp4.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$url = (isset($_POST['url1']) && !empty($_POST['url1'])) ? $_POST['url1'] : false;
if (!$url) {
echo "Vul alstublieft een url in";
} else {
$source = file_get_contents($url);
$source = urldecode($source);
// Verkrijg de video titel.
$vTitle_results_1 = explode('<title>', $source);
$vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
$title = trim(str_replace(' – YouTube', ”, trim($vTitle_results_2[0])));
// Extract video download URL.
$dURL_results_1 = explode('url_encoded_fmt_stream_map', "url1=", $source);
$dURL_results_2 = explode('u0026quality', $dURL_results_1[1]);
// Force download van d video.
$file = str_replace(' ', '_', strtolower($title)).'.mp4';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mp4");
header("Content-Transfer-Encoding: binary");
readfile($dURL_results_2[0]);
exit;
}
}
?>
Updated:
Form submitted for MP3 form works.
But form submitted for MP4 doesn't works.
Please provide an solution to make it work.
php html download include mp3
php html download include mp3
edited Feb 11 '14 at 11:42
brimble2010
11.9k52240
11.9k52240
asked Jan 27 '14 at 16:45
Rene
4,47831223
4,47831223
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Only first php file calls are working because of the following if condition:
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
Since downloadmp3.php has been included first therefore it's if condition
is giving the result.
Use proper form handler to make it work.
Also the best practice is to use unique names for the forms.
add a comment |
up vote
0
down vote
This code is working fine for me in all the browsers and the downloaded file is playing good :
download-audio.php
<?php
$file = $_GET['file'];
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));
readfile($file);
exit;
?>
test.html
<a href='download-audio.php?file=duetsong.mp3'>Download Duet song MP3</a>
<a href='download-audio.php?file=duetsong.mp4'>Download Duet song MP4</a>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Only first php file calls are working because of the following if condition:
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
Since downloadmp3.php has been included first therefore it's if condition
is giving the result.
Use proper form handler to make it work.
Also the best practice is to use unique names for the forms.
add a comment |
up vote
0
down vote
Only first php file calls are working because of the following if condition:
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
Since downloadmp3.php has been included first therefore it's if condition
is giving the result.
Use proper form handler to make it work.
Also the best practice is to use unique names for the forms.
add a comment |
up vote
0
down vote
up vote
0
down vote
Only first php file calls are working because of the following if condition:
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
Since downloadmp3.php has been included first therefore it's if condition
is giving the result.
Use proper form handler to make it work.
Also the best practice is to use unique names for the forms.
Only first php file calls are working because of the following if condition:
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
Since downloadmp3.php has been included first therefore it's if condition
is giving the result.
Use proper form handler to make it work.
Also the best practice is to use unique names for the forms.
answered Feb 11 '14 at 11:49
Akhilesh
8771128
8771128
add a comment |
add a comment |
up vote
0
down vote
This code is working fine for me in all the browsers and the downloaded file is playing good :
download-audio.php
<?php
$file = $_GET['file'];
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));
readfile($file);
exit;
?>
test.html
<a href='download-audio.php?file=duetsong.mp3'>Download Duet song MP3</a>
<a href='download-audio.php?file=duetsong.mp4'>Download Duet song MP4</a>
add a comment |
up vote
0
down vote
This code is working fine for me in all the browsers and the downloaded file is playing good :
download-audio.php
<?php
$file = $_GET['file'];
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));
readfile($file);
exit;
?>
test.html
<a href='download-audio.php?file=duetsong.mp3'>Download Duet song MP3</a>
<a href='download-audio.php?file=duetsong.mp4'>Download Duet song MP4</a>
add a comment |
up vote
0
down vote
up vote
0
down vote
This code is working fine for me in all the browsers and the downloaded file is playing good :
download-audio.php
<?php
$file = $_GET['file'];
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));
readfile($file);
exit;
?>
test.html
<a href='download-audio.php?file=duetsong.mp3'>Download Duet song MP3</a>
<a href='download-audio.php?file=duetsong.mp4'>Download Duet song MP4</a>
This code is working fine for me in all the browsers and the downloaded file is playing good :
download-audio.php
<?php
$file = $_GET['file'];
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));
readfile($file);
exit;
?>
test.html
<a href='download-audio.php?file=duetsong.mp3'>Download Duet song MP3</a>
<a href='download-audio.php?file=duetsong.mp4'>Download Duet song MP4</a>
answered Sep 10 '16 at 0:15
Senthil
7591515
7591515
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21386537%2fdownloading-mp3-and-mp4-files-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown