User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,511 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,116 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 330 | Replies: 14
Reply
Join Date: Jul 2008
Posts: 20
Reputation: phouse512 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
phouse512 phouse512 is offline Offline
Newbie Poster

Another Problem

  #1  
Jul 22nd, 2008
I can't seem to get the fopen thing to work, or otherwise, I'm just stupid if it is but I don't know it.

Here is the code:

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <HEAD>
  4. <title>Open the file</title>
  5. </HEAD>
  6.  
  7. <body>
  8.  
  9. <?php
  10.  
  11. $fp = fopen("http://www.mydomain.org/order.txt", "a+");
  12. fclose($fp);
  13.  
  14. ?>
  15.  
  16. </body>
  17.  
  18. </html>

If that should work, how would I be able to tell, or should I add something to see if it works.

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 396
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 78
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Another Problem

  #2  
Jul 22nd, 2008
  1. $fp = fopen("http://www.mydomain.org/order.txt", "a+");
  2. if($fp){
  3. echo "file opened";
  4. }
  5. else{
  6. echo "file did not open";
  7. }
Lost time is never found again.
- Benjamin Franklin
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 771
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 63
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Master Poster

Re: Another Problem

  #3  
Jul 22nd, 2008
This should answer your question
http://us3.php.net/manual/en/function.fread.php
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.†- Dr. Seuss
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: phouse512 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
phouse512 phouse512 is offline Offline
Newbie Poster

Re: Another Problem

  #4  
Jul 22nd, 2008
Alright, your idea (buddylee) worked, by telling me that the file did not open, but how can I get the file to open? This is the big problem that I have been having.
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 396
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 78
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Another Problem

  #5  
Jul 22nd, 2008
Do you have access to the server? Your host may have the functions disabled. If you are not sure, place the following into a new php file and name it phpinfo.php:
  1. <?php
  2. phpinfo();
  3. ?>
This page will output all of apaches settings. What you should look for is under PHP Core. The directive is named disable_functions. If fopen is disabled, it will be listed here. Just a thought.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: phouse512 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
phouse512 phouse512 is offline Offline
Newbie Poster

Re: Another Problem

  #6  
Jul 22nd, 2008
Do you mean this?

Directive Local Value Master Value
allow_url_fopen On On

Or this one:

disable_functions no value no value

And since I own that website, and since I can save other files to that folder, I'm pretty sure that I have access, or does it have to do with the folder permissions thing? The permissions code for the folder that I want to open the file in is "drwxr-xr-x".
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: phouse512 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
phouse512 phouse512 is offline Offline
Newbie Poster

Re: Another Problem

  #7  
Jul 22nd, 2008
Would you want to see the actual phpinfo file?
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 396
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 78
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Another Problem

  #8  
Jul 22nd, 2008
No, it was just a hunch. Can you test a local file? Create a text file, type a couple of words in it to give it some testable content and save it as testFile.txt in the same directory as your current script. Now run the following:
  1. <?php
  2. $file="testFile.txt";
  3. $fp = fopen($file, "a+");
  4. if($fp){
  5. echo "file opened ";
  6. }
  7. else{
  8. echo "file did not open ";
  9. }
  10. if(filesize($file)!=0)
  11. {
  12. $contents = fread($fp, filesize($file));
  13. echo $contents;
  14. }
  15. else
  16. {
  17. echo "The file is empty";
  18. }
  19. fclose($fp);
  20. ?>
Note that the script checks filesize before attempting fread. You'll get an error attempting fread if the file is 0.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote  
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation: johnsquibb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: Another Problem

  #9  
Jul 23rd, 2008
I believe you can only use a write mode such as 'a+' with fopen on a remote file if using ftp:// as the protocol...even so, you would have to have appropriate ftp permissions to write/append. More about that here:

http://us.php.net/manual/en/features.remote-files.php
The End
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: phouse512 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
phouse512 phouse512 is offline Offline
Newbie Poster

Re: Another Problem

  #10  
Jul 23rd, 2008
It worked, and inside the text file I put in the words Hi, and this is what was outputted:

file opened Hi

So opening files work if it's already there, but I can't create new ones for some reason
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC