Page 1 of 1

ftp fopen overwrite

Posted: Mon Jul 02, 2007 9:00 am
by aye
Hey everyone,
i am having some troubles opening a file for writing over ftp.
Running this code

Code: Select all

fopen("ftp://$ftp_user_name:$ftp_user_pass@$ftp_server/$ftp_file", "w")
gives me the following error:

[function.fopen]: failed to open stream: Remote file already exists and overwrite context option not specified.<br /> FTP server reports 213 26441

i have never worked with ftp and php together, and i have no idea how to solve this. searching the internet for this error does not give very much. any help would be great

Posted: Mon Jul 02, 2007 9:11 am
by volka
try

Code: Select all

<?php
$context = stream_context_create(array(
		'ftp'=>array(
			'overwrite' => true
		)
	)
);
fopen("ftp://$ftp_user_name:$ftp_user_pass@$ftp_server/$ftp_file", "w", false, $context);

Posted: Mon Jul 02, 2007 9:15 am
by aye
thanks for the fast and helpful reply, volka! works great now