Page 1 of 1

[solved] Need help with php ftp functions

Posted: Sat Sep 29, 2007 5:34 am
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?

Posted: Sat Sep 29, 2007 6:25 am
by jeffery
use ftp_connect first

http://php.net/ftp_connect

Posted: Sat Sep 29, 2007 6:28 am
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!

Posted: Sat Sep 29, 2007 6:39 am
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?

Posted: Sat Sep 29, 2007 6:55 am
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.

Posted: Sat Sep 29, 2007 7:06 am
by aye
Ok, problem solved. Thanks for your help, jeffery. I had to rewind the file before putting it.