[solved] Need help with php ftp functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

[solved] Need help with php ftp functions

Post by aye »

Hi everyone,
This is my first time trying to upload something with php through ftp. The idea is to upload a certain string to a new file and this is my current code:

Code: Select all

// FTP connection is set up here -- \\

$tempfile = tmpfile();
fwrite( $tempfile, $file );
    
ftp_fput( $this->ftph, $this->conf['ftp']['tdir'] . $file_name, $tempfile, FTP_ASCII );
	  
fclose( $tempfile );
I am certain that the variable $file contains a value, but still the uploaded file is blank! what am i doing wrong?
Last edited by aye on Sat Sep 29, 2007 7:06 am, edited 1 time in total.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

use ftp_connect first

http://php.net/ftp_connect
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post by aye »

thanks for your reply.
I only posted a part of the code. You can replace "// FTP connection is set up here -- \\ " with ftp_connect and ftp_login functions. The connection is not the problem however, as the temp file is put to the ftp server, but there is nothing in it!
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

login to the FTP server with the ftp credentials. When you login what folder you see is the FTP root. can you navigate to the path shown in the "$this->conf['ftp']['tdir']" variable ? Does the folder exist?
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post by aye »

yea, the folder exists. the actual put operation works fine (no errors or anything) and a file with the correct filename is uploaded to the server, but there is nothing in it. like the 'tempfile' was empty.
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post by aye »

Ok, problem solved. Thanks for your help, jeffery. I had to rewind the file before putting it.
Post Reply