I have a function to download files from my own website(1) server directory and I need to make a function where I will be able to download from my cloned website(1)server directory through my website(1) download function, can anyone help me?
My download function:
function download($file){ //assign value from $row->file from data_ebook page
$this->load->helper('download');
$data2=file_get_contents("./assets/files/".$file);
$name=$file;
force_download($name,$data2);
}
NOTE: It doesn't matter if I can use the same function or I need to make another same function
Update: I just made another download function with a simple modification to the download function, so I simply add my clone website address directory into file_get_contents. So the code will be like this:
function download2($file){ //assign value from $row->file from data_ebook page
$this->load->helper('download');
$data2=file_get_contents("http://localhost/121212a/assets/files/".$file);
$name=$file;
force_download($name,$data2);
}
It's work but I don't know if it's because run in the same localhost or not. and I also don't know if it's safe for my website if I make it online or not, since I use direct directory?
You are facing CORSS problem. Cross-origin resource sharing (CORS) is a mechanism that allows many resources (eg fonts, JavaScript, etc.) on a web page to be requested from another domain outside the domain from which the resource originated You have to enable CORSS on Apache server or in your php header
<?php
header("Access-Control-Allow-Origin: *");
write these line in your .htaccess file
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin http://www.yourfirstsite.com
Header set Access-Control-Allow-Credentials true
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.