Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Error - fopen()


PHP Error - fopen()

Reply
  #1 (permalink)  
Old 04-24-07, 07:36 PM
witakr's Avatar
witakr witakr is offline
Newbie Coder
 
Join Date: Apr 2007
Location: San Angelo, TX
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Error - fopen()

I am getting this error:
Quote:
Warning: fopen(http://www.****.com/scorekeeper/playerfiles/jason.txt) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/witakr/public_html/scorekeeper/processpoints.php on line 33
when i run this code:

PHP Code:

<?php
$sitepath 
"http://www.****.com/scorekeeper/";

  if( !
$playername ) {
   echo 
"You need to enter a playername";
   exit; }

  if( 
$addpoints <= or !$addpoints ) {
   echo 
"You need to enter a points value that is greater than zero.<br><a href='".$sitepath."index.php'>[ Go Back ]</a>";
   exit; }
   
    
$pnlower strtolower($playername);
    
$playerfile "playerfiles/".$pnlower.".txt";
   

    echo 
$playername."<br>";
    echo 
$addpoints."<br>";
    echo 
"File name: ".$playerfile;

  


    
$ps fopen("$sitepath$playerfile""w");
    
    
?>



Can someone help me find my problem? I just don't see it

thanks
j

Last edited by Nico; 04-24-07 at 07:40 PM.
Reply With Quote
  #2 (permalink)  
Old 04-24-07, 07:40 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Open the file in rb mode, and not w.

PHP Code:

$ps fopen("$sitepath$playerfile""rb"); 

EDIT:

Is that your whole code? If you want to write to the file, it needs to be on your server and you have to use the path without the http.

If you just want to read from the file you need to open it in "read" mode, and it should work with http paths, as long as allow_url_fopen is enabled in your php.ini file.

Last edited by Nico; 04-24-07 at 07:44 PM.
Reply With Quote
  #3 (permalink)  
Old 04-24-07, 07:44 PM
witakr's Avatar
witakr witakr is offline
Newbie Coder
 
Join Date: Apr 2007
Location: San Angelo, TX
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
beautiful, thank you so much


EDIT:

Quote:
Is that your whole code? If you want to write to the file, it needs to be on your server and you have to use the path without the http.

If you just want to read from the file you need to open it in "read" mode, and it should work with http paths, as long as allow_url_fopen is enabled in your php.ini file.

Yes, Im trying to Open, write/overwrite, close and then open, read, echo later on

But I am learning this as i go... I havent written php in about 2 years and even then i only knew how to use flat files.. no sql...lol... but I am in the process of learng the write and read parts...lol... I have atut book for php but if you could offer any suggestions.. it would be great

Last edited by witakr; 04-24-07 at 07:47 PM.
Reply With Quote
  #4 (permalink)  
Old 04-24-07, 08:03 PM
witakr's Avatar
witakr witakr is offline
Newbie Coder
 
Join Date: Apr 2007
Location: San Angelo, TX
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, I added write code and its not producing an error but its not writing either


PHP Code:

<?php
$sitepath 
"http://www.****.com/scorekeeper/";

  if( !
$playername ) {
   echo 
"You need to enter a playername<br><a href='".$sitepath."index.php'>[ Go Back ]</a>";
   exit; }

  if( 
$addpoints <= or !$addpoints ) {
   echo 
"You need to enter a points value that is greater than zero.<br><a href='".$sitepath."index.php'>[ Go Back ]</a>";
   exit; }
   
    
$pnlower strtolower($playername);
    
$playerfile "playerfiles/".$pnlower.".txt";
   

    echo 
$playername."<br>";
    echo 
$addpoints."<br>";
    echo 
"File name: ".$playerfile;

  


    
$ps fopen("$playerfile""rb");
    if(!
$ps){
      echo 
"Unable to write to file(".$playerfile.", Contact system administrator";
      }
      else {
     
$scorewrite $playername." - ".$addpoints;
    
fwrite($ps$scorewrite);
    
fclose($ps);
    }
?>

Last edited by witakr; 04-24-07 at 08:29 PM.
Reply With Quote
  #5 (permalink)  
Old 04-24-07, 08:27 PM
witakr's Avatar
witakr witakr is offline
Newbie Coder
 
Join Date: Apr 2007
Location: San Angelo, TX
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Ok I changed this and it now writes...lol thanks

PHP Code:

$ps fopen("$playerfile""w+b"); 


Last edited by witakr; 04-24-07 at 08:29 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 08:26 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
PHP / Graphic Developers someotherguy582 Job Offers & Assistance 1 06-05-05 07:40 PM


All times are GMT -5. The time now is 06:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.