0

I have used this code to copy a 45 mb zipfile from A server to B server.

    <?php
set_time_limit(0);
$file = 'https://www.xxxxx.com/Products.zip';
$newfile = 'Products.zip';

if ( copy($file, $newfile) ) {
    echo "Copy success!";
}else{
    echo "Copy failed.";
}
?>

After copying 17 mb itis giving server error.

I have used some other codes to download or copy from server to server like

<?php
 set_time_limit(0);
    $url  = 'https://www.mydomaind.com/Products.zip';

    $path = 'Products.zip';

    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $data = curl_exec($ch);

    curl_close($ch);

    file_put_contents($path, $data);

echo 'done';

?>

Another one

<?php
set_time_limit(0);
$source =("https://www.mydomaind.com/Products.zip");
$destination = 'Produtcs.zip';

$data = file_get_contents($source);

$handle = fopen($destination, "w");
fwrite($handle, $data);
fclose($handle);
echo 'done';

?>

These last to code download or copy files like 5 mb easily. But when itry to same job for 50 mb. Gives error.

Please helpme how i can do that. Thanks

lospicos
  • 181
  • 4
  • 16

4 Answers4

0

Your hitting php limit.

Look inside php.ini and up the limit

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

p.s. you should not use PHP for sending files between servers.

Better use SSH and SCP. PHP can lunch commands with exec() than you use shell to send file.

  • I can not go to php.ini on my hosting. Doesnt let me. I am on godaddy. – lospicos Dec 21 '13 at 14:54
  • try ini_set() - If it's not disabled. Else, find a different host or go VPS. EDIT: Are you sure you've checked your GoDaddy control panel? On most hosts, there is an option... – RobAtStackOverflow Dec 21 '13 at 15:11
  • I have tried ini set, ini_set('upload_max_filesize','60'); ini_set('post_max_size','60'); i am waiitng. – lospicos Dec 21 '13 at 15:27
  • Now i got a possibility of downloading till 25 mb.by ujsing a different code bu copy chunk method. – lospicos Dec 21 '13 at 16:15
  • @user43163 I diagnosed your error. It is not my problem that host doesn't allow you editing php.ini file. –  Dec 21 '13 at 16:20
0

If you are hitting your limit, here is another SO answer on how to set it in .htaccess

Changing upload_max_filesize on PHP

Community
  • 1
  • 1
Steve
  • 1,195
  • 1
  • 14
  • 34
  • ini_set('upload_max_filesize','60'); ini_set('post_max_size','60'); used this didnt work. I got 500 internal server error – lospicos Dec 22 '13 at 10:47
0

Sorry to respond here mods, can't comment yet!
Already tried to split/cut the zip into 2/3 parts?
Imho would that solve your prob without any errors from servver side.

Charles
  • 202
  • 4
  • 11
  • i tried somthing like chunk size. BUt it didnt work.ıf you know how i can do better,please tellme – lospicos Dec 22 '13 at 10:43
  • Maybe, just maybe this [link](http://stackoverflow.com/questions/4357073/on-the-fly-zipping-streaming-of-large-files-in-php-or-otherwise?answertab=active#tab-top) where they talk about on-the-fly zipping/downloaden (how to zip that way) could help you a little? – Charles Dec 22 '13 at 13:13
0

Try using this code so that you do not use up the available RAM on your server.

function chunked_copy() {
    # write with buffer, 1 meg at a time, adjustable.
    $buffer_size = 1048576; 
    $ret = 0;
    $fin = fopen("http://www.example.com/file.zip", "rb"); #source
    $fout = fopen("file.zip", "w"); #destination
    while(!feof($fin)) {
        $ret += fwrite($fout, fread($fin, $buffer_size));
    }
    fclose($fin);
    fclose($fout);
    return $ret; # return number of bytes written
}
salmanxk
  • 305
  • 2
  • 19