PDA

View Full Version : creating file and directory error


DsgnrsTLZAdmin
02-08-2004, 06:14 PM
mkdir($username);
$create = fopen("/$username/$username.txt", "w+");
fputs($create, "$username");
fclose($create);




That code creates the directory because i can see it with my ftp client...but it doesnt put the file in the directory...i get this error:

Warning: fopen(/yyy/yyy.txt): failed to open stream: No such file or directory in /var/www/html/forum/users/registerprocessor.php on line 31



why is this? thanks.

DsgnrsTLZAdmin
02-08-2004, 06:18 PM
I put in the full path.. which is..



mkdir($username);
$create = fopen("http://64.141.105.108/forum/users/$username/$username.txt", "w+");
fputs($create, "$username");
fclose($create);



and now i get this error:


Warning: fopen(http://64.141.105.108/forum/users/ii/ii.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /var/www/html/forum/users/registerprocessor.php on line 31



whats that mean?

firepages
02-08-2004, 07:27 PM
don't use a url for write operations use a relative path or file path

eg fopen('http:// etc','w'); // << wont work
fopen('/home/user/blah',''w'); // << will work
as will
fopen('blah','w'); // (would create the file 'blah' in the current working directory)


<?php
mkdir( $username , 0777 ) ;
$fp = fopen("$username/$username.txt", "w+");
fputs($fp, "$username");
fclose($fp);
chmod( $username , 0775 ) ;
?>


the chances are that the directory $username already exists and does not have the correct permissions set allow write operations.

DsgnrsTLZAdmin
02-09-2004, 12:14 AM
the chances are that the directory $username already exists and does not have the correct permissions set allow write operations.



No they dont exist....what the code is for is its making the directory $username and creating a file named $username.txt in that directory just created and it doesnt work. It just creates the directory but not the file...see first post for error.

DsgnrsTLZAdmin
02-09-2004, 12:16 AM
the permissions for the directory created are:

drwxr-xr-x

DsgnrsTLZAdmin
02-09-2004, 08:24 PM
One thing I dont understand abuot the code....why did u change mode? Anyway, it works great. Can't think you enough..

firepages
02-10-2004, 01:22 AM
Hi I chmod()'ded just to show that its generally a good idea as leaving a file or directory open at 0777 could allow other users on the server to `modify` those files.

actually 0775 was a surreal example of what to chmod to :D but choose the mode that you feel is appropriate for the protection that your file requires.