ftp fopen overwrite

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

ftp fopen overwrite

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post by aye »

thanks for the fast and helpful reply, volka! works great now
Post Reply