Category Archives: FTP

How to uploading large(big) files in PHP using .htaccess

Usually, default upload size from a web browser is 2 MB and if this is required to be changed, you can do it using .htaccess file.

  1. Create a .htaccess file in the root folder of web server.
  2. Put the following code in side the .htaccess file and save it.
  3. If the .htaccess file already exists, add the above code to the already existing file.
  4. Make sure there are no blank spaces at the end of the file.

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200

Note: Some servers do not allow to change file upload size using .htaccess so Internal Server Error may appear in this case.

How to do server to server ftp transfer in PHP

It is quite difficult to transfer web site from one server to another. Here is a solution for server to server ftp transfer.

  • Zip the required files as one file. The zipping feature is usually available in your web hosting control panel’s file manager.
  • Upload the below mentioned script on the source server.
  • Run the script on the source server.
  • This will transfer files from one server to the other.
  • Unzip the files on the destination server.
This script can be used for other purposes as well.

<?php
$server = “ftp.you-server.com”; //address of ftp server (leave out ftp://)
$ftp_user_name = “userName”; // Username
$ftp_user_pass = “passwordHere”; // Password
$source = “/home/folder/public_html/filename.ext”;
$dest = “/public_html/filename.ext”;
$mode=”FTP_BINARY”;
$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die(‘Connection attempt failed!’); }

$upload = ftp_put($connection, $dest, $source, FTP_BINARY);

if (!$upload) { echo ‘FTP upload failed!’; }

ftp_close($connection);
echo “done”;
?>