Jump to content

Recommended Posts

Hi,

So i used php's ftp functions to upload large files (range being 10-50 MB) using the following code:

 

 

//upload file using ftp

// set up basic connection

$ftp_server = "/* my FTP Sever */";

$conn_id = ftp_connect($ftp_server);

 

// login with username and password

$ftp_user_name = "/* username */;

$ftp_user_pass = "/* password */";

$ftp_dir='/MYDOMAIN.com/extras/softwares/'.$cat; //$cat is a variable i used..nothing important

 

//$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='../../extras/softwares/'.$cat;

$local_file_name = "file.txt";

$web_location=$web_dir.$local_file_name;

 

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

$destination_file=$ftp_dir.$local_file_name;

 

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

 

// check connection

if ((!$conn_id) || (!$login_result)) {

        echo "FTP connection has failed!";

        echo "Attempted to connect to $ftp_server for user $ftp_user_name";

        exit;

    } else {

        echo "Connected to $ftp_server, for user $ftp_user_name";

    }

 

// upload the file

//$destination_file = "setupFile.exe";

//$source_file = "file.txt";

 

$upload = ftp_put($conn_id, $destination_file, $local_file_name, FTP_BINARY);

 

// check upload status

if (!$upload) {

        echo "FTP upload has failed!";

    } else {

        echo "Uploaded $source_file to $ftp_server as $destination_file";

    }

//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);

//verify file was written

if (file_exists($web_location))

        {

        echo "file was uploaded as $web_location";

        }

else

        {

        echo "Could not create $web_location";

        }

//end if

 

 

 

 

the catch here is that to test if this code works, i set the variable $local_file_name to "file.txt" which is a file thats in the same directory as my source files, but thats not what I want..i want the user to put his own file, like browsing for a file using <input type="file">.

but then when i use ftp_put($conn_id, $destination_file, $local_file_name, FTP_BINARY);

the $local_file_name is the local file..i tried to put the directory of a local file manually but it didnt work either..I want the ftp_put function to upload a file of the user's choosing..can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/63574-using-ftp-to-upload-large-files/
Share on other sites

The user can not submit a file to a webpage via ftp...it will always be sent from the user's browser to the web server using http (at least from an html form...of course IE and FF can act as FTP agents, but then the user wouldn't be submitting a file from a form).

 

Once it's been uploaded to the server by the user (via http) the server can ftp it somewhere else if you choose.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.