/    Sign up×
Community /Pin to ProfileBookmark

I’m having a problem when I try to write a file on my ftp server.

This is the code:

$File = $FileInfo[‘Album_File’];
$Buffer = WHeader($FileInfo);

$ftpCnn = @ftp_connect(FTP_SERVER) or die(“Couldn’t connect to FTP_SERVER”);
$bLogin = @ftp_login($ftpCnn,FTP_USER,FTP_PWD) or die(“Couldn’t login to FTP_SERVER”);

$temp = tmpfile();

if (@ftp_fput($ftpCnn, FTP_ROOT.$File, $temp, FTP_ASCII)) {
$bUpload = TRUE;
} else {
echo “There was a problem while uploading $Filen”;
}
fclose($temp);

@ftp_site($ftpCnn,”CHMOD 0777 “.FTP_ROOT.$File);
$fp = fopen(FTP_ROOT.$File,’w’);
fputs($fp,$Buffer);
fclose($fp);
ftp_close($ftpCnn);

my problem is when I try to fopen the file I get this message:

Warning: fopen(/httpdocs/album.php) [function.fopen]: failed to open stream: No such file or directory .

The file is at the server. wich means that the ftp_fput is working. I think.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 08.2011 — Well, if the FTP location is a different server than where the script is running, then you will not be able to fopen() a file on it via its file path-name. The only way you could normally fopen() it would be via a URL, and only if your PHP configuration has allow_url_fopen enabled.
Copy linkTweet thisAlerts:
@lynxnomadauthorFeb 08.2011 — What I have is this:

[COLOR="Blue"]The lines below put the file on my ftp server.: And It Is working the file is there, the file size is zero.[/COLOR]

$File = $FileInfo['Album_File'];

$Buffer = WHeader($FileInfo);

$ftpCnn = @ftp_connect(FTP_SERVER) or die("Couldn't connect to FTP_SERVER");

$bLogin = @ftp_login($ftpCnn,FTP_USER,FTP_PWD) or die("Couldn't login to FTP_SERVER");

$temp = tmpfile();

if (@ftp_fput($ftpCnn, FTP_ROOT.$File, $temp, FTP_ASCII)) {

$bUpload = TRUE;

} else {

echo "There was a problem while uploading $Filen";

}

fclose($temp);

[COLOR="Blue"]What I want to do is now that the file is the and it is empty I want to write in the file[/COLOR]

@ftp_site($ftpCnn,"CHMOD 0777 ".FTP_ROOT.$File);

$fp = fopen(FTP_ROOT.$File,'w'); [COLOR="Red"]<--- this is where the file is, but for some reason return this.:

Warning: fopen(/httpdocs/album.php) [function.fopen]: failed to open stream: No such file or directory .[/COLOR]


And before you guys ask,I try to use different combination for path like.:

"/path/"


"path/"

Erery simgle example that i can find on the web has the same implementation, what I'm missing?



fputs($fp,$Buffer);

fclose($fp);

ftp_close($ftpCnn);
Copy linkTweet thisAlerts:
@NogDogFeb 08.2011 — See my previous reply. FTP is for accessing files between separate servers (hosts). fopen() is for accessing a file via the local server's file system. Simply using a path name like "/directory/file" will be on the current host, [b]not[/b] on a remote host you were connecting to via FTP. Just because the constant you are using is named "FTP_ROOT" does not mean that the PHP code somehow then knows to access that directory via FTP instead of via the local file system -- it just uses that constant's value as the local file system directory name in this case.
Copy linkTweet thisAlerts:
@lynxnomadauthorFeb 08.2011 — so basically all samples on internet wont work?

So How can I do open a file on the server and write inside of it?

So For what I read just now on FTP functions, I should create the file first locally and the upload to the server with ftp_put.
Copy linkTweet thisAlerts:
@NogDogFeb 08.2011 — Not really knowing what you are trying to do, I cannot be positive, but I suspect your last comment makes sense: create the file with the desired comment, [i]then[/i] transfer it to the other server via FTP when it's ready. (Then delete the local copy if you don't need to save it locally for any reason.)
Copy linkTweet thisAlerts:
@lynxnomadauthorFeb 08.2011 — OK. I will explain.:

What I'm trying to do is when my client create a photo album, It will generate a php file that then will be upload to the server.

I thought that I could just upload a file to the server and then write on It at the server.

With those line.:

ftp_fput($ftpCnn, FTP_ROOT.$File, $temp, FTP_ASCII)

fp = fopen(FTP_ROOT.$File,'w').

Very unusual I think ?
×

Success!

Help @lynxnomad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...