Matthew Costello
asked on
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_filesi ze', '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.1 93';
if(!empty($_FILES["uploadf ile"])) {
$uploaddir='/home/cust2/us erxxxxxxx/ html/ma_up loads/';
//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["upload file"]["na me"], $_FILES["uploadfile"]["tmp _name"], FTP_BINARY)) {
echo("file uploaded");
} else {
echo ("error!");
$errormsg = $_FILES['uploadfile']['err or'];
echo $errormsg;
}
}
}
?>
<form action="ma_sock6.php" method="post" enctype="multipart/form-da ta">
<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/ht ml/ma_uplo ads/BestLe vicommerci alever.mpg : No such file or directory in /home/cust2/user1287447/ht ml/ma_sock 6.php on line 224
error!1
error! 1 is the return of $_FILES['uploadfile']['err or']; 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.1 93';
// 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/us erxxxxxxx/ html/ma_up loads/';
$destination_file = $uploaddir.$_FILES['upload file']['na me'];
$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']['err or'];
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-da ta">
<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/ht ml/ma_uplo ads/allmem test.rtf: No such file or directory in /home/cust2/user1287447/ht ml/ma_sock 7.php on line 237
FTP upload has failed!
Files Error 0
(larger file size)
Warning: ftp_put(): /home/cust2/user1287447/ht ml/ma_uplo ads/BestLe vicommerci alever.mpg : No such file or directory in /home/cust2/user1287447/ht ml/ma_sock 7.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/costel lo/html/dh pt/ma_sock 7_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/costel lo/html/dh pt/ma_sock 7_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.
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_filesi
Even and htaccess file with:
RewriteEngine on
RewriteCond %{HTTP:Authorization} !^$
RewriteRule^news_admin.php
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.1
if(!empty($_FILES["uploadf
$uploaddir='/home/cust2/us
//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["upload
echo("file uploaded");
} else {
echo ("error!");
$errormsg = $_FILES['uploadfile']['err
echo $errormsg;
}
}
}
?>
<form action="ma_sock6.php" method="post" enctype="multipart/form-da
<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/ht
error!1
error! 1 is the return of $_FILES['uploadfile']['err
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.1
// 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/us
$destination_file = $uploaddir.$_FILES['upload
$source_file = $_FILES['uploadfile']['tmp
// 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']['err
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-da
<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/ht
FTP upload has failed!
Files Error 0
(larger file size)
Warning: ftp_put(): /home/cust2/user1287447/ht
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/costel
FTP upload has failed!
Files Error 0
Warning: ftp_put(): Rename/move failure: No such file or directory in /home/content/c/o/s/costel
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
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.
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.
ASKER
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.
I'm basing my conclusion on hernst42's response.
Thank to both of you.
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!