LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2006, 11:44 AM   #1
xiekke
LQ Newbie
 
Registered: Feb 2006
Posts: 14

Rep: Reputation: 0
creating file with php


i am learning php with fedora core 4, i wrote the code
*******************************************************
$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
*******************************************************
in my /var/www/html/firstphp.php, and opened it with my browser http://localhost/firstphp.php
and it says "can't open file", however, if the file never existed, it would now be created, quoted by www.tizag.com

" The file "testFile.txt" should be created in the same directory where this PHP code resides. PHP will see that "testFile.txt" does not exist and will create it after running this code. "

there is nothing called testFile.txt in my /var/www/html
 
Old 03-13-2006, 11:54 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The webserver (apache?) probably does not have write-access to /var/www/html. Try /tmp to start with.
 
Old 03-13-2006, 03:33 PM   #3
xiekke
LQ Newbie
 
Registered: Feb 2006
Posts: 14

Original Poster
Rep: Reputation: 0
know how to chnge the permission?
 
Old 03-13-2006, 04:13 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Just don't change the permission of /var/www and below, as it is bad practice (security holes).

Write the file in another directory where apache has write permission, like /tmp or /var/tmp.

Or create a directory dedicated for this, e.g. /home/htfiles. Then make apache (or www-data) the owner of that directory. To find out who the owner should be, view this through your php-webserver:
PHP Code:
<?php
        system
("whoami");
?>
On my PC (debian) the script above says "www-data", so I'd do:
Code:
mkdir /home/htfiles
chown www-data /home/htfiles
And have you PHP script write the file to that directory.
 
Old 03-14-2006, 09:40 AM   #5
xiekke
LQ Newbie
 
Registered: Feb 2006
Posts: 14

Original Poster
Rep: Reputation: 0
i did chown apache /home/phpfile
and wrote the above script called firstphp2.php in that folder, and when i type localhost/firstphp2.php in my browser, it says the page is not found
is anything else i need to do?
i also did, /home/phpfile/firstphp2.php in my browser, but it starts to ask me what kind of tool should i open the php file with, so i don't think that is right
or is there some other way that lets me executes the php file with out using the browswer

Last edited by xiekke; 03-14-2006 at 09:44 AM.
 
Old 03-14-2006, 11:40 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by xiekke
i did chown apache /home/phpfile
and wrote the above script called firstphp2.php in that folder, and when i type localhost/firstphp2.php in my browser, it says the page is not found
You didn't get it:
Leave the PHP script where it was before, just have the script write its file to /home/phpfile:
Code:
$ourFileName = "/home/phpfile/testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
 
Old 03-14-2006, 06:08 PM   #7
xiekke
LQ Newbie
 
Registered: Feb 2006
Posts: 14

Original Poster
Rep: Reputation: 0
ooo thanx dumb me
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
when creating a *.iso file, how to make the file size smaller? minm Linux - Newbie 8 12-26-2004 09:58 PM
Creating a linux user through php taqs Programming 6 08-24-2004 12:29 PM
Creating page tabs w/ php linux_pioneer Programming 1 07-22-2004 12:58 PM
creating shortcuts and dealing with PHP includes xwastedmindx Linux - General 1 02-14-2004 05:22 PM
Creating form with PHP absolut Linux - Newbie 1 01-21-2004 01:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration