• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3408
  • Last Modified:

How do I bypass the php.ini filesize restriction using PHP's FTP function

My webhost for the account this site/script is on has a strict restriction of 2MB for uploads through PHP. No method I know to bypass it works.

I've tried dropping a php.ini into the directory for the site as I can on some other hosts.

I've tried setting the max file sze in the document with ini_set('upload_max_filesize', '10485760');

Even and htaccess file with:

 RewriteEngine on
RewriteCond %{HTTP:Authorization} !^$
RewriteRule^news_admin.php $news_admin.php?login=%{HTTP:Authorization}

RewriteEngine On
php_value post_max_size 10M
php_value upload_max_filesize 10M
php_value max_execution_time 6000000


So I started looking for a different solution and came upon a site that recommended the FTP functions in PHP.By using them, it said, the file size imits could be bypassed. It set out a link to the php.ner manual for the FTP functions.

 I've spent the better part of the last two days trying to get some variation of the different scripts to work with both a file that is within the file size limit and one that isn't.

I've also testing it on my prototype server (which has the flexibility to let me change the files size restrictions with the above methods) and the current link that is the clients actual site and is hosted on a different service.

There is a simpler version which will let me upload a smaller file on both servers.

<?php


if (isset($_POST['upload'])) {
error_reporting(E_ALL);

$ftp_user_name=xxxxxxxxxx;
$ftp_user_pass=xxxxxxxxxx;
$ftp_server='207.159.151.193';


if(!empty($_FILES["uploadfile"])) {
    $uploaddir='/home/cust2/userxxxxxxx/html/ma_uploads/';
    //copy the file to some permanent location
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

   if (ftp_put($conn_id, $uploaddir.$_FILES["uploadfile"]["name"], $_FILES["uploadfile"]["tmp_name"], FTP_BINARY)) {
        echo("file uploaded");
    } else {
        echo ("error!");
             $errormsg = $_FILES['uploadfile']['error'];
       echo $errormsg;
    }
}


}
?>


<form action="ma_sock6.php" method="post" enctype="multipart/form-data">
<p>File
    <input type="file" name="uploadfile">
        <INPUT TYPE="submit" name="upload" value="upload">
    </p>
</form>

This works for both file sizes on my prototype server, but only for the smaller on the clients server.

The error I get on larger file is:
Warning: ftp_put(): /home/cust2/user1287447/html/ma_uploads/BestLevicommercialever.mpg: No such file or directory in /home/cust2/user1287447/html/ma_sock6.php on line 224
error!1


error! 1 is the return of $_FILES['uploadfile']['error']; which I understand means the file size exceeds the limit.

You can see it working on the prototype server her:

http://costello-media.com/dhpt/ma_sock6_dev.php

but not on the client server here:
 
http://damienhowellpt.com/ma_sock6.php

So I went back to the pphp.net example for a ftp upload and tried to work form that script and add what I was petty sure was working from the simpler script:

      <?php
if (isset($_POST['upload'])) {
error_reporting(E_ALL);

$ftp_user_name=xxxxxxx;
$ftp_user_pass=xxxxxxx;
$ftp_server='207.159.151.193';
// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name<br>
<br>
";
    }
 
 $uploaddir='/home/cust2/userxxxxxxx/html/ma_uploads/';
 $destination_file =  $uploaddir.$_FILES['uploadfile']['name'];
 $source_file = $_FILES['uploadfile']['tmp_name'];
 
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
        echo "FTP upload has failed! <br><br>";
$errormsg = $_FILES['uploadfile']['error'];
       echo "Files Error ".$errormsg;
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream
ftp_close($conn_id);
?>
      
      <?php
}
?>


<form action="ma_sock7.php" method="post" enctype="multipart/form-data">
 
  <p>File
    <input type="file" name="uploadfile">
        <INPUT TYPE="submit" name="upload" value="upload">
    </p>
</form>

But thats worse. Neither size file will upload.

I get the following:

(smaller file size)
 Warning: ftp_put(): /home/cust2/user1287447/html/ma_uploads/allmemtest.rtf: No such file or directory in /home/cust2/user1287447/html/ma_sock7.php on line 237
FTP upload has failed!

Files Error 0

(larger file size)
Warning: ftp_put(): /home/cust2/user1287447/html/ma_uploads/BestLevicommercialever.mpg: No such file or directory in /home/cust2/user1287447/html/ma_sock7.php on line 237
FTP upload has failed!

Files Error 1

You can see it here:

http://damienhowellpt.com/ma_sock7.php

On the prototype server Im getting:

(smaller file size)
Warning: ftp_put(): Rename/move failure: No such file or directory in /home/content/c/o/s/costello/html/dhpt/ma_sock7_dev.php on line 237
FTP upload has failed!

Files Error 0



Warning: ftp_put(): Rename/move failure: No such file or directory in /home/content/c/o/s/costello/html/dhpt/ma_sock7_dev.php on line 237
FTP upload has failed!

Files Error 0

You can see it here:

http://costello-media.com/dhpt/ma_sock7_dev.php



So Im coming to think that either:

1)      I dont have a good grip on understanding how the $_FILES array should work or
2)      The original posting I saw was in error: you cant bypass the file size restriction by using the PHP FTP functions. (Or Im just not understanding how its done).

Any help you may offer is appreciated.
0
Matthew Costello
Asked:
Matthew Costello
  • 3
1 Solution
 
hernst42Commented:
You can't bypass the value of 2MB with that code, because for the initial upload of the file via php is limitited to 2M. With that code you upload the file via HTTP (which is limited to 2M) and then you try to move that file via ftp to the same server.

Best way is to ask the hoster to change that limit. If that isn't possible go to another host which has higher limits or where you can set the limits.

FTP might only work if you use another PHP-Server which has higher limits and then transfer the file via ftp to your orginal webserver which has the 2MB limit.
0
 
orbic1Commented:
Do you have webdav enabled? If so - you can use that - you may even be able to go beyond your ISPs restrictions.

On a broader note - hernst42 is right - just ask them! We increased our upload limit to 8Mb for a client when asked. If they still won't - get a Virtual Dedicated Server or Dedicated Server and do it yourself!
0
 
Matthew CostelloAuthor Commented:
hernst42:

Thanks for the response.

OK. So there's no way to do a ftp with PHP from a user to the clients site without HTTP. Is that correct?

I did ask the host to change it. They're firm about the restriction. Yes, I am looking at moving them as an option but I just moved the client six months ago and don't want to charge them for another move and lose a 1/2 year of webhosting if I don't have to.


Seems your final selection is not a for sure way either. Also, I'm not clear how to set it up to do that.
0
 
Matthew CostelloAuthor Commented:
orbic1:

Thanks for your response.

Not sure about webdav - sorry, I'm not familiar with it. Where would I check to see if it's enabled?

As I mentioned to hernst42 I'm trying to avoid another move if I don't have to. Looks like the idea that using the PHP FTP functions to bypass the 2M limit is in error.
0
 
Matthew CostelloAuthor Commented:
Ok. I'm concuding I need to move to another server. The PHP FTP functions do not bypass the size restriction.

I'm basing my conclusion on hernst42's response.

Thank to both of you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now