php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12004 problem with fopen over ftp and a related fgets
Submitted: 2001-07-10 06:07 UTC Modified: 2002-08-11 06:54 UTC
From: koenig at internet24 dot de Assigned: wez (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 4.0.5 OS: linux
Private report: No CVE-ID: None
 [2001-07-10 06:07 UTC] koenig at internet24 dot de
Configure      './configure'       '--with-apxs=/usr/local/apache/bin/apxs'
Command        '--with-mysql'  '--with-pgsql'  '--with-zlib' '--enable-ftp'
               '--with-gd'                 '--with-jpeg-dir=/usr/local/lib'
               '--enable-versioning'              '--enable-track-vars=yes'
               '--enable-url-includes'                   '--enable-sysvshm'
               '--enable-syscsem' '--with-gettext'

<?php
	$file = "user:secret@somewhere.org/path/file.txt";

	if (!($fp = fopen($file, "r+"))) {
		echo "error: can't open file<br>";
		exit;
	}

	fputs($fp, "test number one...");
	fputs($fp, "test number two...");
	fputs($fp, "etc...");

	fclose($fp);
?>
-------------------------------
The problem is, that nothing is written in the file even though fopen,fputs and
fclose do not return an error.

If you use fopen($file, "a+") the strings are written to file. But now
the problem is, that fopen tries to create that file even if it already exists.

Ciao,
Tobias

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-20 22:40 UTC] sniper@php.net
Reproduced with PHP 4.1.0RC1

Seems like this is not supported at all..

--Jani

 [2001-12-17 05:28 UTC] alan_k@php.net
The following patch will issue a warning for trying to open a ftp file in anything other than read/write, - as no other methods are supported by fopen(ftp)

as far as producing errors on 'writing to an ftp file opened read only' - this is more complex as there is no indicators on the socket to tell wheter it was opened read or write,

(internally the socket is opened rw as the actual connection is a 2 way communication)






Index: ftp_fopen_wrapper.c
===================================================================
RCS file: /repository/php4/ext/standard/ftp_fopen_wrapper.c,v
retrieving revision 1.11
diff -u -r1.11 ftp_fopen_wrapper.c
--- ftp_fopen_wrapper.c 9 Sep 2001 13:29:18 -0000       1.11
+++ ftp_fopen_wrapper.c 17 Dec 2001 10:24:06 -0000
@@ -101,6 +101,14 @@
                *issock = BAD_URL;
                return NULL;
        }
+        if (strcmp(mode, "r") &&  strcmp(mode, "w")) {
+               php_error(E_WARNING, "Invalid mode : ftp can only access files in (r)ead or (w)rite mode");
+               php_url_free(resource);
+               *issock = BAD_URL;
+               return NULL;
+        }
+        
+        
        /* use port 21 if one wasn't specified */
        if (resource->port == 0)
                resource->port = 21;

 [2001-12-17 05:33 UTC] alan_k@php.net
browser changed the title for some reason...
 [2002-04-13 15:47 UTC] wez@php.net
We can probably do something about this with the new
streams architecture.
Assigning to myself.
 [2002-08-11 06:54 UTC] wez@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

At last!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC