Jump to content

FTP Upload Script File Size Issues


biwerw

Recommended Posts

I am struggling with getting this script to work. The idea is to have clients upload their large files via a web based site to our in house FTP server.

 

I have gotten it to work error free with file sizes up to approx. 6.7mb. Which leads me to believe its an issue with file size restrictions. I have added the lines

Ini_set("upload_max_filesize","1000M");

and

Ini_set("post_max_size","1000M");

but still receive the below error.

 

Notice: Undefined index: submit in E:\www\mymarketinglab.com\clientlogin\general\upload-file.php on line 63

 

Notice: Undefined index: submit in E:\www\mymarketinglab.com\clientlogin\general\upload-file.php on line 70

 

Any ideas what could cause this?

 

<?

Echo "<!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=UTF-8' />
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='pragma' content='no-cache'>
<title>Portal</title>
<!--CSS-->
<link href='../assets/css/style.css' type='text/css' rel='stylesheet' title='print' media='screen' />

<!--JAVASCRIPT-->
<!--[if lte IE 6]>
<script src='http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js' type='text/javascript'></script>	
<![endif]-->
</head>
<body>
<div id='layout'>
<div id='layout-top'>
    	<div id='top-nav'>
        	<p><a href='upload.php'>« BACK</a> | <a href='../logout.php'>LOGOUT</a></p>
        </div><!--top-nav end-->
    </div><!--layout-top end-->
    <br class='clear' />
    <div id='layout-header'>
        <div class='mlab-type' align='center'><img src='../assets/images/mlab-logo-original-trans.png' alt='Logo' /></div>
    </div><!--layout-header end-->

<div id='layout-content'>
    	<div id='content-top'></div>
        <div id='content-middle'>
            <div align='center'>
            	<img src='../assets/images/label-thankyou-trans.png' alt='Thank You' style='margin:0 auto;' />
";

//uses $_FILES[] global array
//see manual for older PHP version info

//This function will be used to get the extension from the filename
Function get_extension($file,$length=-1){
$p = strrpos($file,".");
$p++;
If($length!=-1){
$ext = substr($file,$p,$length);
}
If($length==-1){
$ext = substr($file,$p);
}
$ext = strtolower($ext);
Return $ext;
}

//reset time limits to not time out on larger files
Ini_set('max_execution_time',0);
Ini_set('max_input_time',0);
Ini_set('set_time_limit',0);

?>

<?
//check to see if we have submited yet
If($_POST["submit"]!="submit"){
//not yet so lets make the form
?>

<?
}
//see if we have submited and that the files array has been set
If(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){

$ftp_user_name="username"; //change to ftp username
$ftp_user_pass="password"; //change to ftp password
$ftp_server="11.111.111.111"; //change to ftp url
$ftp_dump_dir="/upload-general"; //change to destination directory

//Not good practice, but here anyway
//change to suit your needs
//also some have to be set in the ini
//for this to correctly work

//2meg max
Ini_set("upload_max_filesize","1000M");

//turn on file uploads
Ini_set("file_uploads","1");

//set your temp dir
Ini_set("upload_tmp_dir","/tmp");

//set post size large enough to accomidate
//3 100meg files and some overhead
Ini_set("post_max_size","1000M");






//go through all the files
For($x=0;$x<count($_FILES['userfiles']['name']);$x++){

//now we do some file checking

//check to see if file is there
If($_FILES['userfiles']['name'][$x]!="none"){
//file has a name
//check filesize
If($_FILES['userfiles']['size'][$x]!=0){
//file is larger than 0 bytes
//Check to see if it is uploaded
If(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){
//file has been uploaded!
//let the user know their file has be uploaded
Echo "<p>".$_FILES['userfiles']['name'][$x]." uploaded successfully!</p>";
//conect to ftp server
$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 "<p>FTP connection has failed!</p>";
Echo "<p>Attempted to connect to $ftp_server for user $ftp_user_name</p>";
Exit;
} else {
//Echo "<p>Connected to $ftp_server!</p>";
//set PASV mode
If(!ftp_pasv($conn_id,TRUE)){
Echo "<p>Could not enter PASV mode!</p>";
}
//rename to file#_date.Ext
$filename = $_FILES['userfiles']['name'][$x];
//$filename.= ".".Get_extension($_FILES['userfiles']['name'][$x],3);

//change directory
If (@ftp_chdir($conn_id, $ftp_dump_dir)) {
//maybe you want to make sure we are in the correct directory
//Echo "Current directory is now : ", ftp_pwd($conn_id), "\and";
} else {
//you want to know if it didn't work
Echo "Couldn't change directory\and";
}

//upload the file and let the user know what happened
If(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){
//Echo "<p>File ".$_FILES['userfiles']['name'][$x]." was sent successfully</p>";
//Echo "<p>File was named ".$filename."</p>";
}else{
Echo "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";;
}
}
// close the FTP stream
Ftp_close($conn_id);
}
Else echo"<p>File was not uploaded!</p>";
}
}

}//end for loop
Echo "<p class='back'><a href='upload.php'>«Back</a></p>";
}

Echo "</div>
  </div><!--content-middle end-->
        <div id='content-bottom'></div>
    </div><!--layout-content end-->

</div><!--layout end-->

</body>
</html>";

?>

 

Thanks!!

 

Link to comment
https://forums.phpfreaks.com/topic/170841-ftp-upload-script-file-size-issues/
Share on other sites

well the message you are seeing is just a notice telling you that the post element "submit" does not exist. so either it doesn't exist in your form, or the form has not been submitted. also, verify you are using POST and not GET, i like to use $_REQUEST which covers both of them...

Both of those settings cannot be set using ini_set() statements. They are both PHP_INI_PERDIR, which means "Entry can be set in php.ini (either the master php.ini or in a local php.ini when php is running as a CGI application), .htaccess (when php is running as an Apache Module) or httpd.conf (Apache web servers only.)"

I've tried editing both a php.ini template as well as one I created with just the edited values I need, both resulted in a page that says the following:

 

This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.

 

For more information as to why this behaviour exists, see the manual page for CGI security.

 

For more information about changing this behaviour or re-enabling this webserver, consult the installation file that came with this distribution, or visit the manual page.

 

I have never adjusted the php setting from the server side and am pretty much learning by doing...

 

Any help would be great.

 

Cannot really help you without knowing what your web host expects in the php.ini and what you put into it. It would be best if you contacted your web host to find the exact method you would need to use to change those settings.

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.