kwheetley Posted July 21, 2009 Share Posted July 21, 2009 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 ?> Quote Link to comment Share on other sites More sharing options...
J.Daniels Posted July 21, 2009 Share Posted July 21, 2009 There is upload_max_filesize set in php.ini which defaults to 2 MB. Quote Link to comment Share on other sites More sharing options...
kwheetley Posted July 21, 2009 Author Share Posted July 21, 2009 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; ?> Quote Link to comment Share on other sites More sharing options...
J.Daniels Posted July 21, 2009 Share Posted July 21, 2009 Does your host allow a custom php.ini? One way to view what settings are loaded is to create a file with: <?php phpinfo(); ?> View that in your web browser and it will list all the PHP settings. Look for upload_max_filesize. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.