toddgeo Posted March 10, 2009 Share Posted March 10, 2009 This is my first post so I apologize if it's not done just right, but I'll try: Goal: I am trying to use a popup form to upload to a specific folder on an ftp using radio buttons to assign a category and then it e-mails me of the upload. There is also a check built in to verify that they did in fact enter something into the e-mail textbox(later to have actual e-mail verification, hopefully) and to also verify that they checked the checkbox(terms of agreement). Problem: Everything seems to work until I get above like 9meg, then it just tells me that I didn't agree to the terms which is the echo it should give if the checkbox is not checked. I'm fairly certain that it's failing on the ftp_nb_put, I've tried ftp_put and it still fails. I've set a variable to the return of the ftp_put and then echo'd that variable for debug purposes, and it returns nothing. So I can't use ftp_continue or whatever to keep the connection alive. I know that maybe I'm just too close to this and missing something stupid, so please accept my thanks ahead of time. The site is http://www.toddgeo.com/george.html First the Form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>George</title> </head> <body> <form id="form1" name="form1" method="post" action="georgetest.php" onsubmit="return checkForm()"enctype="multipart/form-data"> Submit your very own video to Keye-TV to be posted online<br /> <label> <input name="radiobutton" type="radio" value=1 /> test1 radio</label> <p> <label> <input name="radiobutton" type="radio" value=2 /> test2 radio</label> </p> <p> <label> <input name="radiobutton" type="radio" value=3 /> test3 radio</label> </p> <p> <label>email <input type="text" name="email"><br /> </label> </p> <p> <label> <input type="checkbox" name="checkbox" unchecked /> checkbox1</label> </p> <p> </p> <p><input type="file" name="imagefile"></p> <p> <label>buttongo <input type="submit" name="Submit" value="Submit" /> </label> </p> </form> </body> </html> Now the Script:(the login credentials and the server have been replaced with bogus info) <?php //************************VARIABLE DECLARATION****************** //set variables from file grab $imagefile_name=$_FILES["imagefile"]["name"]; $category=$_POST['radiobutton']; //************************************************************* //*******************************Checks if the Checkbox is checked if(!isset($_POST['checkbox'])) {header('location:http://www.toddgeo.com/notagree.html'); die(); }else { //*********************E-MAIL START********************* if(!$_REQUEST["email"]!="")//if "email" is filled out, send email, and continue {header('location:http://www.toddgeo.com/noemail.html'); die(); }else { //**************************FTP START************************************** //ftp settings $ftp_user_name='bob'; $ftp_user_pass='bobspassword'; $ftp_server='ftp.toddgeo.com'; $ftp_dir='/uploads/'; if($category == 1) { $new_dir="uploads/test1/"; } elseif($category == 2) { $new_dir="uploads/test2/"; } elseif($category == 3) { $new_dir="uploads/test3/"; } else { $new_dir="uploads/"; } //$web_location is needed for the file_exists function, the directories used by FTP //are not visible to it will will always return not found. //$web_dir='/uploads/'; $web_location=$imagefile_name; //build a fully qualified (FTP) path name where the file will reside $destination_file=$ftp_dir.$imagefile_name; //echo $destination_file; //debug-lists $destination_file //echo $web_location . "<br />"; //debug-weblocation // connect, login, and transfer the file $conn_id = ftp_connect($ftp_server) or die("Could not connect to server"); //ini_set('max_execution_time', 0); //this didn't make a difference ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); $res = ftp_nb_put($conn_id, $destination_file, $imagefile_name, FTP_BINARY); echo "res= " . $res; //debug - $res is not returning a value, it is completely empty while ($res == FTP_MOREDATA) { $this->_announce('nb_put'); $res = @ftp_nb_continue($this->_handle); } //Move Temp File to permenant placement with given name move_uploaded_file($_FILES["imagefile"]["tmp_name"], $new_dir . $_FILES["imagefile"]["name"]); //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); //send email $to="[email protected]"; $email = $_REQUEST["email"]; $subject = "File Submission"; mail($to, $subject, "From: ".$email." Filename: ".$imagefile_name." Folder: ".$new_dir); //********************E-MAIL END************************* header('Location:http://www.toddgeo.com/thanks.html'); die(); //****************FTP END****************************************** } } ?> Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/ Share on other sites More sharing options...
redarrow Posted March 10, 2009 Share Posted March 10, 2009 look these up and use them with a .htaccess file for that project only.. file_uploads upload_max_filesize max_input_time memory_limit max_execution_time post_max_size Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781275 Share on other sites More sharing options...
redarrow Posted March 10, 2009 Share Posted March 10, 2009 read this as well http://uk2.php.net/manual/en/function.ftp-set-option.php <?php // Set the network timeout to 10 seconds ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 10); ?> Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781279 Share on other sites More sharing options...
kev wood Posted March 10, 2009 Share Posted March 10, 2009 you didnt do to bad for your first post just put all your code inside code tags it makes it easier to read and you will find you get more replies (the code tags button is the # symbol). i have problems uploading large files to the server before, although it was not exactly the same as you have done here i found that putting the following code at the top of the php script for the upload allowed the larger files to be uploaded. set_time_limit(0); if i remember correctly this allows the code to continue running before the server connection is lost. Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781282 Share on other sites More sharing options...
redarrow Posted March 10, 2009 Share Posted March 10, 2009 and look at your form it wrong format. <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> << where this mate. and read about set_time_limit() function. http://uk2.php.net/set_time_limit Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781286 Share on other sites More sharing options...
toddgeo Posted March 10, 2009 Author Share Posted March 10, 2009 So I think that I've tried the suggestions given, here is the code again reposted, with suggested changes. I've tried to keep my timeouts set to 5 minutes and my file sizes set at no less than 16M. I'm still getting the same thing where that the script is eventually just dumping back to the first check and then forwarded on to the notagree.html. I can also prove that the ftp_put isn't returning anything. The php.ini: rg_emulation=off php_value upload_max_filesize 16M php_value post_max_size 20M php_value max_input_time 1000 php_value max_execution_time 2000 The Form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>George</title> </head> <body> <form id="form1" name="form1" method="post" action="georgetest.php" onsubmit="return checkForm()"enctype="multipart/form-data"> Submit your very own video to Keye-TV to be posted online<br /> <label> <input name="radiobutton" type="radio" value=1 /> test1 radio</label> <p> <label> <input name="radiobutton" type="radio" value=2 /> test2 radio</label> </p> <p> <label> <input name="radiobutton" type="radio" value=3 /> test3 radio</label> </p> <p> <label>email <input type="text" name="email"><br /> </label> </p> <p> <label> <input type="checkbox" name="checkbox" unchecked /> checkbox1</label> </p> <p> </p> <input type="hidden" name="MAX_FILE_SIZE" value="30000000" /> <p><input type="file" name="imagefile"></p> <p> <label>buttongo <input type="submit" name="Submit" value="Submit" /> </label> </p> </form> </body> </html> The Script: <?php //************************VARIABLE DECLARATION****************** //set variables from file grab $imagefile_name=$_FILES["imagefile"]["name"]; $category=$_POST['radiobutton']; set_time_limit(0); //Didn't make a difference //************************************************************* //*******************************Checks if the Checkbox is checked if(!isset($_POST['checkbox'])) {header('location:http://www.toddgeo.com/notagree.html'); die(); }else { //*********************E-MAIL START********************* if(!$_REQUEST["email"]!="")//if "email" is filled out, send email, and continue {header('location:http://www.toddgeo.com/noemail.html'); die(); }else { //**************************FTP START************************************** //ftp settings $ftp_user_name='toddgeo'; $ftp_user_pass='F0rg1v3n'; $ftp_server='ftp.toddgeo.com'; $ftp_dir='/uploads/'; if($category == 1) { $new_dir="uploads/test1/"; } elseif($category == 2) { $new_dir="uploads/test2/"; } elseif($category == 3) { $new_dir="uploads/test3/"; } else { $new_dir="uploads/"; } //$web_location is needed for the file_exists function, the directories used by FTP //are not visible to it will will always return not found. //$web_dir='/uploads/'; $web_location=$imagefile_name; //build a fully qualified (FTP) path name where the file will reside $destination_file=$ftp_dir.$imagefile_name; //echo $destination_file; //debug-lists $destination_file //echo $web_location . "<br />"; //debug-weblocation // connect, login, and transfer the file $conn_id = ftp_connect($ftp_server) or die("Could not connect to server"); ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 300); ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); set_time_limit(360); $res = ftp_nb_put($conn_id, $destination_file, $imagefile_name, FTP_BINARY); while ($res == FTP_MOREDATA) { $this->_announce('nb_put'); $res = @ftp_nb_continue($this->_handle); } //Move Temp File to permenant placement with given name move_uploaded_file($_FILES["imagefile"]["tmp_name"], $new_dir . $_FILES["imagefile"]["name"]); //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); //send email $to="[email protected]"; $email = $_REQUEST["email"]; $subject = "File Submission"; mail($to, $subject, "From: ".$email." Filename: ".$imagefile_name." Folder: ".$new_dir); //********************E-MAIL END************************* //verify file was written if (file_exists($web_location)) { echo "file was uploaded as $web_location"; } else { header('Location:http://www.toddgeo.com/thanks.html'); die(); } //****************FTP END****************************************** } } ?> Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781421 Share on other sites More sharing options...
toddgeo Posted March 10, 2009 Author Share Posted March 10, 2009 Just a little added information, I thought I would use just an "echo "hello";" statement placed in the script code to figure out where things were getting.. "hung up." If I put it in front of the first check, it always shows up, however if I put it after the else statement, then it depends on the size of the file submitted. Nowhere in that conditional am I checking size or even polling the file in any way so why does that matter at this point in the code? //*******************************Checks if the Checkbox is checked if(!isset($_POST['checkbox'])) {header('location:http://www.toddgeo.com/notagree.html'); die(); }else { Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-781597 Share on other sites More sharing options...
kev wood Posted March 11, 2009 Share Posted March 11, 2009 i have just been doing some reading on this and i read that if you set in your .htaccess file the php_value max_execution_time to 0 then this implies unlimited script execution time. this may not be the fix but give it a try it wont hurt. if your server is running PHP 5 you cannot set the upload_max_filesize using a .htaccess file or the ini_set() method. if that is the case then you will need to install the php.ini master file in the directory that you want to change the upload_max_filesize. if your PHP handler is CGI, you must use php.ini. Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-782045 Share on other sites More sharing options...
toddgeo Posted March 11, 2009 Author Share Posted March 11, 2009 I do have PHP 5, and that's why I'm using the php.ini file for the settings. I don't have a .htaccess file at all, maybe that is my problem? Link to comment https://forums.phpfreaks.com/topic/148785-ftp-is-timing-out/#findComment-782068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.