Jump to content
Sign in to follow this  
Aaron

Php Ftp

Recommended Posts

I'm trying to use the php ftp functions, but I can't seem to get them to work. Is the PHP ftp enabled on the server?

 

I'd really appreciate it if someone who has already used the php ftp functions would share their code cuz I'm really not getting anywhere.

 

Thanks,

Aaron

Share this post


Link to post
Share on other sites

I'm actually pursuing two different methods, first is the move_uploaded_file() method, and next is the ftp_put method(). I'm gonna outline what I know below, just in case there is a flaw in my logic somewhere.

 

In the first case, I use a standard html form, with an input with type=file:

 

><FORM ACTION='ftp.php?submit=1' METHOD='POST' ENCTYPE="MULTIPART/FORM-DATA">
        <INPUT TYPE="FILE" NAME="file">
        <BUTTON TYPE="SUBMIT">UPLOAD</BUTTON>
</FORM>

 

Once the user clicks on the Upload button, I run this script:

 

>$upload_dir = "public_html/uploads/"
$filename = $_FILES['file']['name'];
$tempname = $_FILES['file']['tmp_name'];
move_uploaded_file($tempname, $upload_dir . $filename);

 

I basically just copied the example off of the php manual for handling file uploads: PHP Manual: Handling File Uploads

 

I tried this locally on my laptop with IIS and PHP, and it works, but it doesn't work on my TCH site. I figure that the problem is either that I need the full path to my account, OR this method is just not supported by TCH.

 

So I then tried PHP's ftp methods. I didn't even use any kind of form:

 

>$ftp_connection = ftp_connect($ftp_server);
$login = ftp_login($ftp_connection, $ftp_username, $ftp_password);
ftp_put($ftp_connection, "/public_html/uploads/file.doc", "C:\file.doc", FTP_BINARY);

 

That's it. Again, the code is pretty much lifted off the PHP manual. The problems I see here are that I might just need the full path to my folder on the TCH server, or my reference to "C:\file.exe" is just wrong ... I only know the basic differences between the Linux and Windows directory structures ("\" vs. "/", Windows has drive letters), so I might just be missing something there.

 

Thanks for any help on this guys! I'd also appreciate it if the forum moderators could chime in on whether ftp is enabled on the php, and whether or not I do need the full path.

 

 

Aaron

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Sign in to follow this  

×
×
  • Create New...