Skip navigation

I had some success today finishing up a small project I had been wanting to work on whenever I had time.  I wanted to be able to transfer uploaded artwork from our website directly to a file server via FTP.  We have been using built-in PHP functions to create and move the uploaded files into folders, but it was residing on our webserver.  I wanted to connect to a file server so that our site gets a little more portable (I could run the site elsewhere and the files should show up here) and to reduce the number of people who need access to the webserver itself.  Here’s what I came up with:

//FTP connection
$conn = ftp_connect(“serverAddress”) or die(“Could not connect”);
ftp_login($conn,”FTPUser”,”FTPPass”);
//make directory
ftp_mkdir($conn,$FolderName);
//change directory to newly created one
ftp_chdir($conn,$FolderName);
//put temp PHP files in new folder
ftp_put($conn,$_FILES[‘FileField’][‘name’],$_FILES[‘FileField’][‘tmp_name’],FTP_BINARY);
ftp_close($conn);

Seems simple enough, I just had doubts to if the FTP functions could extract the $FILES information. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: