By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,617 Members | 1,166 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,617 IT Pros & Developers. It's quick & easy.

upload ftp

P: n/a
HI,

I have follow problem. I want upload a file to a map on a ftp server.

I make a connection to a ftp server. That's ok.
Then I make a directory

ftp_chdir($conn_id,"/public_html/info"); //ok

if(ftp_mkdir($conn_id,"uploads")) print ("File is created!"); //ok

ftp_chdir($conn_id,"/public_html/info/uploads"); //ok ?????

$source_file = $_FILES['userfile']['name']; //ok exist (is a file from
the local drive

$destination ="/public_html/info/uploads"; //I think that's the map I make

$upload = ftp_fput($conn_id, $source_file , $destination_file, FTP_BINARY);

print $upload gives false

The error in the browser :

File is created!
/public_html/info/uploads

Warning: ftp_fput() expects parameter 3 to be resource, string given in
/home/school/public_html/result.php on line 37
FTP upload has failed!

What's wrong?

thxt,

Alain

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Alain Dhaene" <al**********@worldonline.be> wrote in message news:<bv**********@news.worldonline.be>...
HI,

I have follow problem. I want upload a file to a map on a ftp server.

I make a connection to a ftp server. That's ok.
Then I make a directory

ftp_chdir($conn_id,"/public_html/info"); //ok

if(ftp_mkdir($conn_id,"uploads")) print ("File is created!"); //ok

ftp_chdir($conn_id,"/public_html/info/uploads"); //ok ?????

$source_file = $_FILES['userfile']['name']; //ok exist (is a file from
the local drive

$destination ="/public_html/info/uploads"; //I think that's the map I make

You are already in /public_html/info/uploads directory, as you have
done *ftp_chdir* to change the current working directory at server.

The syntax for *ftp_fput* is:

bool ftp_fput ( resource ftp_stream, string remote_file, resource
handle, int mode [, int startpos] )

So, modify your code accprdingly:

$source_file = $_FILES['userfile']['name'];>
$destination_file = "remote_filename";

$fp = fopen($source_file, 'r');

ftp_fput ( $conn_id,$destination_file,$fp, FTP_BINARY );

ftp_close($conn_id);
fclose($fp);

--
Hope it will help,
Rahul Anand
Jul 17 '05 #2

P: n/a
HI,
I rewrite the code but i seems it doesn't works.
$source_file = "course.txt";
$destination_file = "copy.txt"; //but this txt doesn't exist yet. I want
put the $source_file (local drive) on the ftp server.(in the map uploads)

$fp = fopen($source_file, 'r');

ftp_fput ( $conn_id,$destination_file,$fp, FTP_BINARY );

I get follow errors:

Warning: fopen(cursisten.txt): failed to open stream: No such file or
directory in /home/school/public_html/result.php on line 29

cursisten.txt

Warning: ftp_fput() expects parameter 3 to be resource, boolean given in
/home/school/public_html/result.php on line 43

Alain


"Rahul Anand" <ra************@rediffmail.com> schreef in bericht
news:62**************************@posting.google.c om...
"Alain Dhaene" <al**********@worldonline.be> wrote in message

news:<bv**********@news.worldonline.be>...
HI,

I have follow problem. I want upload a file to a map on a ftp server.

I make a connection to a ftp server. That's ok.
Then I make a directory

ftp_chdir($conn_id,"/public_html/info"); //ok

if(ftp_mkdir($conn_id,"uploads")) print ("File is created!"); //ok

ftp_chdir($conn_id,"/public_html/info/uploads"); //ok ?????

$source_file = $_FILES['userfile']['name']; //ok exist (is a file from the local drive

$destination ="/public_html/info/uploads"; //I think that's the map I make

You are already in /public_html/info/uploads directory, as you have
done *ftp_chdir* to change the current working directory at server.

The syntax for *ftp_fput* is:

bool ftp_fput ( resource ftp_stream, string remote_file, resource
handle, int mode [, int startpos] )

So, modify your code accprdingly:

$source_file = $_FILES['userfile']['name'];>
$destination_file = "remote_filename";

$fp = fopen($source_file, 'r');

ftp_fput ( $conn_id,$destination_file,$fp, FTP_BINARY );

ftp_close($conn_id);
fclose($fp);

--
Hope it will help,
Rahul Anand

Jul 17 '05 #3

P: n/a
"Alain Dhaene" <al**********@worldonline.be> wrote in message news:<bv**********@news.worldonline.be>...
HI,
I rewrite the code but i seems it doesn't works.
$source_file = "course.txt";
$destination_file = "copy.txt"; //but this txt doesn't exist yet. I want
put the $source_file (local drive) on the ftp server.(in the map uploads)
$destination_file contains just the file name, a plain string
variable.

That means your local file will be uploaded to ftp server with name
$destination_file


$fp = fopen($source_file, 'r');
I guess problem is here. Please provide file name (if not in current
local directory, give full path, relative or absolute). Ensure your
local file is placed there.
ftp_fput ( $conn_id,$destination_file,$fp, FTP_BINARY );

I get follow errors:

Warning: fopen(cursisten.txt): failed to open stream: No such file or
directory in /home/school/public_html/result.php on line 29

cursisten.txt

Warning: ftp_fput() expects parameter 3 to be resource, boolean given in
/home/school/public_html/result.php on line 43

Alain


Hope it will help.

--
Rahul Anand
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.