Jump to content

PHP FTP Upload Form


kwheetley

Recommended Posts

Hey guys. I just heard of PHP yesterday, lol, but I'm trying to make a script for a submit button on my form using FTP. My goal is to allow someone to upload a very big file to a specific folder on my server. Using the script that I have, all files that are < 2M are received on the server, but anything > 2M and I get a 'File cannot be empty' error and no transfer. Is PHP FTP the correct choice for me? And how to I get it to allow larger files of any kind, like videos, pictures, docs, etc.? Thanks for you help! Below is my script for the button (which is on another webpage).

 

<?php

 

//change these values to suit your site

$ftp_user_name='********';

$ftp_user_pass='*******';

$ftp_server='ftp.mysite.com';

$ftp_dir='Uploads/';

 

 

//build a fully qualified (FTP) path name where the file will reside

$destination_file=$ftp_dir.$_FILES['File'] ['name'];

 

// connect, login, and transfer the file

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$upload = ftp_put($conn_id, $destination_file, $_FILES['File'] ['tmp_name'], FTP_BINARY);

 

//use ftp_site to change mode of the file

//this will allow it be visible by the world,

$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);

// close the FTP stream

ftp_close($conn_id);

 

 

//end if

 

?>

Link to comment
https://forums.phpfreaks.com/topic/166806-php-ftp-upload-form/
Share on other sites

Thank you for your response, but I have a custom php.ini file set in place. It seems it isn't working though. I reveive the message saying it's modified and copied. Here it is.

 

<?php

// Put all the php.ini parameters you want to change below. One per line.

// Follow the example format $parm[] = "parameter = value";

$parm[] = "register_globals = Off";

$parm[] = "upload_max_filesize = 30M";

$parm[] = "post_max_size = 10M";

$parm[] = "session.use_trans_sid = 0";

// full unix path - location of the default php.ini file at your host

// you can determine the location of the default file using phpinfo()

$defaultPath = "/usr/local/lib/php.ini";

// full unix path - location where you want your custom php.ini file

$customPath = "/home/****/****/****/Uploads/php.ini";

// nothing should change below this line.

if (file_exists($defaultPath)) {

  $contents = file_get_contents($defaultPath);

  $contents .= "\n\n; USER MODIFIED PARAMETERS FOLLOW\n\n"; 

  foreach ($parm as $value) $contents .= $value . " \n";

  if (file_put_contents($customPath,$contents)) {

    if (chmod($customPath,0600)) $message = "The php.ini file has been modified and copied";

      else $message = "Processing error - php.ini chmod failed";

  } else {

    $message = "Processing error - php.ini write failed";

  }

} else {

  $message = "Processing error - php.ini file not found";

}

echo $message;

?>

Link to comment
https://forums.phpfreaks.com/topic/166806-php-ftp-upload-form/#findComment-879644
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.