Search the Community
Showing results for tags 'download'.
-
I want to backup mp3 files from a server folder to a local folder can this be done in php which is server side. I tried many scripts claiming to do this but all result in 'failed to open stream: No such file or directory' because the code is looking for the destination on the server, not the local directory. Here is an example that says it can be done. ini_set('display_errors',1); error_reporting(E_ALL); $source = "https://domain.com/2024-2021/path_to_file/test.mp3"; echo "src is ", $source; $destination = "C:/backup/2024-2021/Cpath_to_file/"; file_put_contents($destination, file_get_contents($source)); echo "OK"; This one also claims to 'force' the download $file = '/path/to/files/photo.jpg'; if (is_file($file)) { sendHeaders($file, 'image/jpeg', 'My picture.jpg'); $chunkSize = 1024 * 1024; $handle = fopen($file, 'rb'); while (!feof($handle)) { $buffer = fread($handle, $chunkSize); echo $buffer; ob_flush(); flush(); } fclose($handle); exit; } But has the same problem, in that it fails when opening the local folder to write the file, is there a way to do this?
-
I have a download section in my index.php that I'd like to add a download counter to but have no idea how to accomplish this. The existing code works perfectly but I'd like to know how many times the file is downloaded. Would prefer not to use a database. <!-- DOWNLOAD --> <div id="download" class="stylized"> <div "myform"> <div class="container"> <div class="row"> <div class="download"> <br /><br> <h1><center>FoxClone Download Page</center></h1> <?php $files = glob('download/*.iso'); $file = $files[count($files) -1]; $info = pathinfo($file); $filename = basename($file); $filename = ltrim($filename,'/'); $md5file = md5_file($file); ?> <div class="container"> <div class="divL"> <h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3> <center> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center><br /> <h3 style="margin-bottom: 0.5rem;">The MD5sum for "<?php echo "{$filename}";?>" is "<?php echo "{$md5file}";?> Thanks in advance, Larry
-
Hello guys i need to add php script for downloading mp4 and mp3 files on my website [redacted] any help i need the codes please.
-
So I am creating a small file manager to manage uploaded files into a certain directory on my sever. I have created the attached code, but the issue is that when I click the download button, the webpage (html file) itself gets downloaded instead of the file in the directory that is supposed to be downloaded. Please note that there is no upload file type restrictions, so there are any file type you can imagine in this directory. I can't recognize the error in my code. Any help will be highly appreciated and that you in advance <html> <head> <title>My first PHP Page</title> </head> <body> <table border="1"> <?php $dir = 'uploads'; $files = scandir($dir); sort($files); $count = -1 ; foreach ($files as $file) { $v_download = "download_".$count; $v_delete = "delete_".$count; $v_rename = "rename_".$count; $fileName = $file; if ($file != '.' && $file != '..') { echo "<tr>"; echo "<td>"; echo $count; echo "</td>"; echo "<td>"; echo $file; echo "</td>"; echo "<td>"; echo "<form action='' method='post'><input type='submit' value='Download' name='".$v_download."'/></form>"; if(isset($_POST[$v_download])) { $filename = $_POST[$file]; header('Content-type: '.filetype($filename).'/'.pathinfo($filename, PATHINFO_EXTENSION)); header('Content-Disposition: attachment; filename="'.$filename.'"'); readfile('uploads/'.$filename); exit(); } echo "</td>"; echo "<td>"; echo "<form action='' method='post'><input type='submit' value='Delete' name='".$v_delete."'/></form>"; if(isset($_POST[$v_delete])) { // Your php delete code here echo "delete file : ".$file; } echo "</td>"; echo "<td>"; echo "<form action='' method='post'><input type='submit' value='Rename' name='".$v_rename."'/></form>"; if(isset($_POST[$v_rename])) { // Your php rename code here echo "rename file : ".$file; } echo "</td>"; echo "</tr>"; } $count++; } ?> </table> </body> </html> list.html