Creating File to SPECIFIC directory

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
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Creating File to SPECIFIC directory

Post by genetix »

I'm creating a file manager but I cant figure out how to get this code block to work. Its to create a file in the users folder.

The page is created. Its just in the same dirrectory of the script.

$file = files name ex. index.php
$username = logged in user only consisting of letters
$wdpage = variable with information saying like page coming soon.

Code: Select all

$filefull = "C:/AppServ/www/hosting/$username/$file";
$handle = fopen("$file", "a");
fwrite($handle, $wdpage);
fclose($handle);
peni
Forum Commoner
Posts: 34
Joined: Thu Nov 18, 2004 1:15 pm

Post by peni »

look for the premissions and try to escape the backslashes:

Code: Select all

$filefull = "C:\\AppServ\\www\\hosting\\$username\\$file";
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

look at the fopen call....

your creating the file named $file
you need to create $filefull

btw- peni, at least win xp,
C:\foo\file

has never been any diff than

C:/foo/file


for me

ive never had an issue when not using win style backslashes as dir seperators
peni
Forum Commoner
Posts: 34
Joined: Thu Nov 18, 2004 1:15 pm

Post by peni »

very true.
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

I fixed the error where $file should have been $filefull but it still doesn't work. Heres the errors:

Warning: fopen(C:/AppServ/www/hosting/WebDummy/works.php): failed to open stream: No such file or directory in c:\appserv\www\webdummy\www\serverpro\page_create.php on line 95

Warning: fwrite(): supplied argument is not a valid stream resource in c:\appserv\www\webdummy\www\serverpro\page_create.php on line 96

Warning: fclose(): supplied argument is not a valid stream resource in c:\appserv\www\webdummy\www\serverpro\page_create.php on line 97

oh ya and I thought I would add. The server is running on Windows XP.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if your trying to create the file:

C:/AppServ/www/hosting/WebDummy/works.php

make sure that this exists and is writable

C:/AppServ/www/hosting/WebDummy/

fopen cannot create directories
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

Thanks, I got it working again. The problem was that Web Dummy is my site so I had it setup in a local folder instead of hosting. I was trying to save to a dirrectory that didn't exist :oops:


Thanks again.
Post Reply