0

I have to download large size file > xxx MB/GB using PHP code. How can i download this? I ve wrote this code but I can't download biggest < 45 mb. But I need download lass then 1 GB..

<?php
##Simple download file for URL's##

if(isset($_POST['download'],$_POST['downloadurl'])) {
    $downloadurl = htmlspecialchars($_POST['downloadurl']);
    if(!empty($downloadurl)) {
        if (@fopen($downloadurl, "r")) {
            $file = basename($downloadurl);
            if(copy($downloadurl, $file)) {
                echo "Fayl serverga ko'chirildi! <br />";
                echo '<textarea>'.$_SERVER['HTTP_HOST'].'/'.$file.'</textarea>';
            } else {
                echo "We're sorry we can't download this file!";    
            }
        } else {
            echo "This url is empty or not file!";
        }   
    } else {
        echo "Please enter url filei!"; 
    }

    exit(); 
}


echo '<form action="download.php" method="post">
    URL FILE: <br /><input type="text" name="downloadurl" ><br />
    <input type="submit" name="download" value="submit">';
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • 1
    Some sensible code indentation makes your code easier to read and therefore also easier to debug!! – RiggsFolly Jan 13 '17 at 09:20
  • 1
    @thebluefox That dup is about sending file to the user, not uploading files to the server !!!! – RiggsFolly Jan 13 '17 at 09:23
  • I think you need to read the PHP Manual. It places uploaded files in an array called `$_FILES` and not in `$_POST` [Read this section of the manual - Handling file uploads](http://php.net/manual/en/features.file-upload.php) – RiggsFolly Jan 13 '17 at 09:27
  • Might also be worth looking at CURL; gives you more granular control : http://stackoverflow.com/questions/6409462/downloading-a-large-file-using-curl and http://php.net/manual/en/book.curl.php – CD001 Jan 13 '17 at 09:28
  • 1
    I'm voting to **close this question** as off-topic because the OP is so far off the mark the only solution is to point them to the manual or give them a whole tutorial – RiggsFolly Jan 13 '17 at 09:30
  • You **either** for `fopen` **or** do `copy`. Both make no sense. Also do you want to copy the file on your server or download it on the client? – apokryfos Jan 13 '17 at 09:33
  • @apokryfos - I'm pretty sure he's just using `fopen()` to check that the file is available for reading before copying it... not the right thing to do but there is a kind of warped logic to it. – CD001 Jan 13 '17 at 09:41
  • I'm pretty sure that the objective here is to enter an URL into a form and have the web server copy a file from a remote server to itself - nothing being *"uploaded"* or *"downloaded"* as such, but copying a file from one server to another - I could be wrong. There are better tools for this but that's what the objective *appears* to be. – CD001 Jan 13 '17 at 09:41

0 Answers0