opencart download from new server - php

Actually i want to change opencart download routh to new website, already download folder is:
/system/download
config.php
define('DIR_DOWNLOAD', '/system/download/');
and here is code from controller/account/download.php
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info['filename'];
$mask = basename($download_info['mask']);
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) {
ob_end_clean();
}
readfile($file, 'rb');
exit();
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->response->redirect($this->url->link('account/download', '', 'SSL'));
}
i want to buy a new server just for downloading, and now i want change opencart download route to new server. how can i do this?
Already download system is like this:
https://example.com/index.php?route=account/download/download&download_id=16
and it will get file from this directory:
/system/download/example.zip
but i want to get file from new server:
https://newserver.com/download/example.zip
Is it possible? I changed DIR_DOWNLOAD but no success. Any idea?

Yes you can, go with this easily:
$newserv = "http://newserver.com/";
$file = $newserv . $download_info['filename'];
$mask = basename($download_info['mask']);

Related

Resume Download Links in PHP

The following file (which I don't understand it at all) serves my requested file and makes it ready to be downloaded. But, the links that are created and served by this file miss really important items when downloading by IDM.
File size: (unknown), Time left (unknown) , Resume capability (unknown).
Very unprofessional and bad in all aspects. What should I do as a novice?
if (isset($status) && ($status == 'd')) { //if Every Thing Is Fine The Download Start
$filename = $url;
$extension = fileexten($filename);
$fakename = fakefilename($downcode);
$mime = contenttype($extension);
// set_time_limit(0);
if ($notadownload == FALSE) {
header('Pragma: public');
header('Expires: 0');
header("Content-Type:" . $mime);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Disposition: attachment;filename=' . $fakename . '.' . $extension);
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
#readfile($filename);
} else {
$mime = getContentType($filename);
header("Content-Type:" . $mime);
if (strpos($mime, 'text') == FALSE) {
$extension = fileexten($filename);
header('Content-Disposition: inline;filename=' . $fakename . '.' . $extension);
}
echo #file_get_contents($filename);
}
}

Youtube video download working fine on localhost but not working on live (Production) server

I am working on a php file, where i can put youtube video url, it gives me the download link, when i click on that download button on localhost, video starts downloading, but when i put it on live, it does not work.
This is code for button
echo ' ' . '<b>Record MP4</b>';
Here is the code behind that button download button
include_once('config.php');
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
$size=get_size($url);
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Content-Length: '.$size);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
}
else
{
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Content-Length: '.$size);
header('Pragma: no-cache');
}
readfile($url);
exit;
}
// Not found
exit('File not found 8{');
It always give me error that invalid download token, but on localhost, it works properly. Why it won't work when it is live?

PHP File Serving using X-Sendfile

I'm building a website with a file serving script.
This script allows the website to deliver pdf, mp3 and mp4 files.
But only PDF and MP3 files were working.
By clicking on the play video, I'im expecting the video file to play but it's not. The video controls have been disabled and unable to play.
files.php
<?php
error_reporting(E_All);
$fid = $_GET['fid'];
$ftype = $_GET['ftype']; // e.g. audios, videos, ebooks
$fcat = isset($_GET['cat']) ? $_GET['cat'] . '/' : ''; // e.g. lessons, more
$fext = '';
$fmime = '';
switch ($ftype) {
case 'ebooks':
$fext = '.pdf';
$fmime = 'application/pdf';
break;
case 'audios':
$fext = '.mp3';
$fmime = 'audio/mp3';
break;
default:
$fext = '.mp4';
$fmime = 'video/mp4';
break;
}
// example: audios/lessons/audio1.mp3
$file = $ftype . '/' . $fcat . str_replace('s', '', $ftype) . $fid . $fext;
if (file_exists($file))
{
// open the file as binary mode
$fp = fopen($file, 'rb');
// send the right headers
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-type: ' . $fmime);
header('Content-Length: ' . filesize($file));
// dump the file then stop the program
fpassthru($fp);
exit;
}
else
{
die('File loading failed.');
}
video.php
<video src="/products/files.php?fid=1&ftype=videos&cat=lessons" autoplay controls></video>
alternatively, to the address bar
mydomain.com/products/files.php?fid=1&ftype=videos&cat=lessons
Could anyone else find out what I did wrong? Thanks in advance.
I finally solved this problem with the use of X-Sendfile apache module
<?php
if (file_exists($file))
{
// send the right headers
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-type: ' . $fmime);
header('Content-Length: ' . filesize($file));
// Make sure you have X-Sendfile module installed on your server
// To download this module, go to https://www.apachelounge.com/download/
header('X-Sendfile: ' . $file);
exit;
}
else
{
die('File loading failed.');
}

Youtube downloader script on server end

I am trying to generate a script which can download youtube videos on the server, I would like the user to provide the video url.
I have searched a lot but, could not make it work. Here's my code.
<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{/*
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
*/}
else
{/*
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
*/}
$download_video_file = file_put_contents($file_path, fopen($url, 'r'));
exit;
}
// Not found
exit('File not found 8{');
?>
But I am still stuck at this, Please help me out.
You will get the code from here
Ref : https://code.google.com/p/php-youtube-downloader/
<?php
require_once('youtube.lib.php');
$download_link = get_youtube('http://www.youtube.com/watch?v=SAQZ0BDXn48');
// we will have array here, index 0 is the video ID and index 1 is the download link.
echo $download_link[1];
?>
http://php-youtube-downloader.googlecode.com/files/youtube_downloader.zip
GitHub : https://github.com/jeckman/YouTube-Downloader

Download YouTube video in server

I have created a YouTube search engine + download + MP3 convert script. I have used Jeckman's YouTube Downloader for creating this script. Everything is OK, except, I want to download the video into the server instead it downloading it to my computer. I want to do this because, after it gets download, I shall convert the video to MP3 using FFmpeg.
Is there any way to get the video downloaded in my server instead of my computer?
The download.php contains the following code:
<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
}
else
{
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
}
readfile($url);
exit;
}
// Not found
exit('File not found 8{');
?>
I've found out a solution to store the YouTube file to server. I have removed the header stuff and put $download_video_file = file_put_contents($file_path, fopen($url, 'r')); in place of readfile($url); and it worked like a magic! ^_^
Here's the complete code:
<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{/*
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
*/}
else
{/*
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
*/}
$download_video_file = file_put_contents($file_path, fopen($url, 'r'));
exit;
}
// Not found
exit('File not found 8{');
?>

Categories