-1

I have to make the php max file upload to the 50 GB. The server has the capability but I have confusion that how this task should be accomplished.

My first question: Is it possible to upload a 50 GB file at once in php?

Second question: if possible, is there any way to upload the file in chunks so it would better if the connection lost due to some reason so it will continue from the chunks which are left and the uploaded chunks will remain in server.

Sorry, I have not much experience in PHP and never do such a task. I try to google but couldn't find any solution.

Thanks

  • Does this answer your question? https://stackoverflow.com/questions/10399336/upload-large-files-to-ftp-with-php – smartdroid Jun 17 '20 at 17:09
  • Does this answer your question? [Upload large files to FTP with PHP](https://stackoverflow.com/questions/10399336/upload-large-files-to-ftp-with-php) – smartdroid Jun 17 '20 at 17:10
  • You ask about one solution, but what is the issue you try to solve? THEN someone can even help in a better way. ... or is PHP a must have? – simUser Jun 17 '20 at 22:33

2 Answers2

0

1. It's possible but it depends on many factors like your internet connection (execution timeout), PHP version and PHP settings.

post_max_size = 0
upload_max_filesize = 0

2. It's shouldn't be considered sending such big files without chunking. It can be achieved using other protocols than HTTP (which is not recommended) and with JS/PHP.

Look at other answers, because this topic was mentioned many times and there are many libraries for this, i.e. Upload 1GB files using chunking in PHP

Jsowa
  • 9,104
  • 5
  • 56
  • 60
0

To upload a large file you can consider the two most important things

  • Good internet connection
  • Upload file chunk by chunk

I use the below code to upload a large file that is greater than 5MB. You can increase the chunk size. Although I don't know your file type. You may try.

/**
 * @param $file
 * @param $fileSize
 * @param $name
 * @return int
 */
public function chunkUpload($file, $fileSize, $applicantID, $name) {
    
    $targetFile     = 'upload/'. $name;
    $chunkSize      = 256; // chunk in bytes
    $uploadStart    = 0;

    $handle = fopen($file, "rb");
    $fp     = fopen($targetFile, 'w');

    # Start uploading
    try {
    
        while($uploadStart < $fileSize) {
        
            $contents = fread($handle, $chunkSize);
            fwrite($fp, $contents);
        
            $uploadStart += strlen($contents);
            fseek($handle, $uploadStart);
        }
    
        fclose($handle);
        fclose($fp);
        
        return 200;
        
    } catch (\Exception $e) {
        return 400;
    }
}
RASEL RANA
  • 2,112
  • 1
  • 15
  • 17