RE: [PHP] Opening a file

2007-09-07 Thread Sanjeev N


Here there may be 2 cases.
1st either file() is not returning any values, that is why array empty and
wrong datatype error, are you able to read the file.

2nd try to use implode function to consider each word as different value in
an array
$lines = implode('', file("fruits.txt"));

Warm Regards,
Sanjeev
http://www.sanchanworld.com/
http://webdirectory.sanchanworld.com - Submit your website URL
http://webhosting.sanchanworld.com - Choose your best web hosting plan

-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 05, 2007 7:55 PM
To: php-general
Subject: [PHP] Opening a file

Good Morning!

Opening this file is proving to be a pain. I have a folder that contains a
PHP page and a text file. I am trying to open the contents of the txt file
using file() but it keeps erroring out. Below is the code I'm using to try
and open it:



So, I'm setting my variable, opening my file as an array in $lines, then
checking to see if my variable is in the array, and if it is, assign a value
ot a new variable.  However, I am getting the following error:

PHP Warning: in_array()
[function.in-array<http://develop1/credit%20card%20processing/function.in-ar
ray>]:
Wrong datatype for second argument

Any ideas?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Dan Shirah
Ah, okay.

Would this also work if I wanted to apply this to multiple other pages
located within different areas of the site tree?


On 9/5/07, Stut <[EMAIL PROTECTED]> wrote:
>
> Dan Shirah wrote:
> > So:
> > fruits.txt is contained in the same folder as mypage.php.
> > mypage.php tries to pull the data contained in fruits.txt to see if the
> > data matches
> > toppage.php has mypage.php inserted as an include and checks for the
> > result of $a and processes accordingly.
>
> In that case your CWD in mypage.php is two levels above where mypage.php
> is. Change the line that reads the file to...
>
> $lines = file(dirname(__FILE__).'/users.txt');
>
> ...and it should work fine.
>
> -Stut
>
> --
> http://stut.net/
>


Re: [PHP] Opening a file

2007-09-05 Thread brian

Dan Shirah wrote:

Good Morning!

Opening this file is proving to be a pain. I have a folder that contains a
PHP page and a text file. I am trying to open the contents of the txt file
using file() but it keeps erroring out. Below is the code I'm using to try
and open it:



So, I'm setting my variable, opening my file as an array in $lines, then
checking to see if my variable is in the array, and if it is, assign a value
ot a new variable.  However, I am getting the following error:

PHP Warning: in_array()
[function.in-array]:
Wrong datatype for second argument



Have you tried passing the full path to the file? Make sure you use the 
entire filesystem path (from root). If you're not sure what that is, you 
can get it easily like so:


// say your file lives within your site's home at /mydir/fruits.txt

$filepath = "${_SERVER['DOCUMENT_ROOT']}/mydir/fruits.txt";

brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Stut

Dan Shirah wrote:

So:
fruits.txt is contained in the same folder as mypage.php.
mypage.php tries to pull the data contained in fruits.txt to see if the 
data matches
toppage.php has mypage.php inserted as an include and checks for the 
result of $a and processes accordingly.


In that case your CWD in mypage.php is two levels above where mypage.php 
is. Change the line that reads the file to...


$lines = file(dirname(__FILE__).'/users.txt');

...and it should work fine.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Dan Shirah
Toppage.php -


LOTS OF HTML


Mypage.php -


LOTS OF HTML


So:
fruits.txt is contained in the same folder as mypage.php.
mypage.php tries to pull the data contained in fruits.txt to see if the data
matches
toppage.php has mypage.php inserted as an include and checks for the result
of $a and processes accordingly.

On 9/5/07, Stut <[EMAIL PROTECTED]> wrote:
>
> Dan Shirah wrote:
> > I did a
> >
> > if ($lines === false) {
> > echo "lines is false";
> > }
> >
> > like you suggested and it displays that text...but it still make no
> sense.
> > mypage.php and fruits.txt are in the same folder, on the same
> server.  There
> > isn't any permissions issues.
> >
> > So, if mypage.php and fruits.txt are in the same folder, then $lines =
> > file("fruits.txt") should be valid.
>
> Is mypage.php the script you're calling or is it being included from a
> script in a different directory? The 'current directory' is the
> directory of the main script, not included scripts. Use
> dirname(__FILE__) to get the path to the current script.
>
> -Stut
>
> --
> http://stut.net/
>


Re: [PHP] Opening a file

2007-09-05 Thread Stut

Dan Shirah wrote:

I did a

if ($lines === false) {
echo "lines is false";
}

like you suggested and it displays that text...but it still make no sense.
mypage.php and fruits.txt are in the same folder, on the same server.  There
isn't any permissions issues.

So, if mypage.php and fruits.txt are in the same folder, then $lines =
file("fruits.txt") should be valid.


Is mypage.php the script you're calling or is it being included from a 
script in a different directory? The 'current directory' is the 
directory of the main script, not included scripts. Use 
dirname(__FILE__) to get the path to the current script.


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Dan Shirah
mypage.php and fruits.txt have the same permissions.

The IUSR(internet user) account has the following permissions:
Read & Execute
Read




On 9/5/07, Jay Blanchard <[EMAIL PROTECTED]> wrote:
>
> [snip]
> I did a
>
> if ($lines === false) {
> echo "lines is false";
> }
>
> like you suggested and it displays that text...but it still make no
> sense.
> mypage.php and fruits.txt are in the same folder, on the same server.
> There
> isn't any permissions issues.
>
> So, if mypage.php and fruits.txt are in the same folder, then $lines =
> file("fruits.txt") should be valid.
> [/snip]
>
> Are they the same owners? What exactly are the permissions on
> fruits.txt?
>


RE: [PHP] Opening a file

2007-09-05 Thread Jay Blanchard
[snip]
I did a

if ($lines === false) {
echo "lines is false";
}

like you suggested and it displays that text...but it still make no
sense.
mypage.php and fruits.txt are in the same folder, on the same server.
There
isn't any permissions issues.

So, if mypage.php and fruits.txt are in the same folder, then $lines =
file("fruits.txt") should be valid.
[/snip]

Are they the same owners? What exactly are the permissions on
fruits.txt?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Dan Shirah
I did a

if ($lines === false) {
echo "lines is false";
}

like you suggested and it displays that text...but it still make no sense.
mypage.php and fruits.txt are in the same folder, on the same server.  There
isn't any permissions issues.

So, if mypage.php and fruits.txt are in the same folder, then $lines =
file("fruits.txt") should be valid.


On 9/5/07, Richard Davey <[EMAIL PROTECTED]> wrote:
>
> Hi Dan,
>
> Wednesday, September 5, 2007, 3:24:43 PM, you wrote:
>
> > Opening this file is proving to be a pain. I have a folder that contains
> a
> > PHP page and a text file. I am trying to open the contents of the txt
> file
> > using file() but it keeps erroring out. Below is the code I'm using to
> try
> > and open it:
>
> >  > $fruit = "apple");
> > $lines = file("fruits.txt");
> > if (in_array($fruit,$lines))
> >   {
> >   $a = "Y";
> >   }
> ?>>
>
> > So, I'm setting my variable, opening my file as an array in $lines, then
> > checking to see if my variable is in the array, and if it is, assign a
> value
> > ot a new variable.  However, I am getting the following error:
>
> > PHP Warning: in_array()
> > [function.in-array<
> http://develop1/credit%20card%20processing/function.in-array>]:
> > Wrong datatype for second argument
>
> The call to file() has probably failed.
>
> Check to see if $lines === false, if so that is your problem. In which
> case you probably need to address the path to fruits.txt, or check
> file permissions.
>
> Cheers,
>
> Rich
> --
> Zend Certified Engineer
> http://www.corephp.co.uk
>
> "Never trust a computer you can't throw out of a window"
>
>


Re: [PHP] Opening a file

2007-09-05 Thread Richard Davey
Hi Dan,

Wednesday, September 5, 2007, 3:24:43 PM, you wrote:

> Opening this file is proving to be a pain. I have a folder that contains a
> PHP page and a text file. I am trying to open the contents of the txt file
> using file() but it keeps erroring out. Below is the code I'm using to try
> and open it:

>  $fruit = "apple");
> $lines = file("fruits.txt");
> if (in_array($fruit,$lines))
>   {
>   $a = "Y";
>   }
?>>

> So, I'm setting my variable, opening my file as an array in $lines, then
> checking to see if my variable is in the array, and if it is, assign a value
> ot a new variable.  However, I am getting the following error:

> PHP Warning: in_array()
> [function.in-array]:
> Wrong datatype for second argument

The call to file() has probably failed.

Check to see if $lines === false, if so that is your problem. In which
case you probably need to address the path to fruits.txt, or check
file permissions.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Opening a file

2007-09-05 Thread Dan Shirah
Good Morning!

Opening this file is proving to be a pain. I have a folder that contains a
PHP page and a text file. I am trying to open the contents of the txt file
using file() but it keeps erroring out. Below is the code I'm using to try
and open it:



So, I'm setting my variable, opening my file as an array in $lines, then
checking to see if my variable is in the array, and if it is, assign a value
ot a new variable.  However, I am getting the following error:

PHP Warning: in_array()
[function.in-array]:
Wrong datatype for second argument

Any ideas?


RE: [PHP] Opening a file in a new window

2003-03-10 Thread George Pitcher
Todd,

if that script is the result of a link being follwed, add target="blank" to
the end.

George

> -Original Message-
> From: Todd Cary [mailto:[EMAIL PROTECTED]
> Sent: 10 March 2003 5:28 pm
> To: [EMAIL PROTECTED]
> Subject: [PHP] Opening a file in a new window
>
>
>   Thanks to your help, this now is working:
>
>$session_id  = $HTTP_POST_VARS[session_id];
>   $filename= $HTTP_POST_VARS[filename];
>
>   /* Validate session_id here */
>
>   header("Content-type: text/html");
>   header("Content-Disposition: filename=" . $filename);
>   $fp = fopen($filename, "r");
>   if($fp) {
> fpassthru($fp);
> fclose($fp);
>   }
> ?>
>
> Now I would like to open the file in a new window and I am not sure how
> to do that.
>
> Todd
>
> --
> Ariste Software, Petaluma, CA 94952 \n [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Opening a file in a new window

2003-03-10 Thread Todd Cary
 Thanks to your help, this now is working:


 /* Validate session_id here */

 header("Content-type: text/html");
 header("Content-Disposition: filename=" . $filename);
 $fp = fopen($filename, "r");
 if($fp) {
   fpassthru($fp);
   fclose($fp);
 }
?>
Now I would like to open the file in a new window and I am not sure how 
to do that.

Todd

--
Ariste Software, Petaluma, CA 94952 \n [EMAIL PROTECTED]


[PHP] opening a file from internet explorer

2003-02-18 Thread DIKSHA NEEL
hi all,

i have a problem:

i am opening and reading and writing a file through php page.


$fp = fopen("\bdoi_change\andar.html", "w");
fwrite($fp, "dikshai 
solved problem!");

but when i try to open "\bdoi_change\andar.html" through
internet explorer, i am getting "page cannot be displayed".

please help me out.

diksha.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Opening a file to manipulate it

2002-11-20 Thread Tarsy
Try this:

$content = implode('', file('../header.html'));

Or if you're running php 4.3.0 or greater:

$content = file_get_contents('../header.html');

Can't get much easier than that :)

-Mark
PS: That was in the user contributed notes Ed mentioned :)

- Original message -
From: "Troy May" <[EMAIL PROTECTED]>
To: "@ Edwin" <[EMAIL PROTECTED]>
Date: Sat, 16 Nov 2002 21:45:50 -0800
Subject: RE: [PHP] Opening a file to manipulate it

Thanks Ed!  Yes, another member here told me to use fread(), which is
what
your link led to if you're not using the CVS version of PHP.  (whatever
that
is)

I got it working with this:

mailto:[EMAIL PROTECTED]]
Sent: Saturday, November 16, 2002 9:29 PM
To: Troy May
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Opening a file to manipulate it


Hello,

"Troy May" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Extreme newbie here (halfway through my first book :) ).  I need to open a
> file, read the whole file into a variable, manipulate it, and then echo it
> to the screen.  I'm doing it right from my book and it's not working.
> Here's what I have now:
>
> 
> echo $header; ?>
>
> It writes "Resource id #1" at the top of the page.  What is that?!  :)

Check the manual:

  http://www.php.net/manual/en/function.fopen.php

You're echoing the result of fopen() which is an "int"--you have to make
sure that you're using the function properly ;)

> I have also tried using file().  That displays "Array" on the screen.
What
> am I doing wrong?

I think it's because you're echoing the result of file() which is an
array.
You cannot just "echo $the_array;" Try print_r($the_array) and you'll see
a
different result--though I doubt it's the one you want to see :)

Check the manual again:

  http://www.php.net/manual/en/function.file.php

Anyway, I think you're looking for something like this:

  http://www.php.net/manual/en/function.file-get-contents.php

Esp. the "User Contributed Notes".

HTH,

- E


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Opening a file to manipulate it

2002-11-20 Thread Troy May
Thanks Ed!  Yes, another member here told me to use fread(), which is what
your link led to if you're not using the CVS version of PHP.  (whatever that
is)

I got it working with this:

mailto:[EMAIL PROTECTED]]
Sent: Saturday, November 16, 2002 9:29 PM
To: Troy May
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Opening a file to manipulate it


Hello,

"Troy May" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Extreme newbie here (halfway through my first book :) ).  I need to open a
> file, read the whole file into a variable, manipulate it, and then echo it
> to the screen.  I'm doing it right from my book and it's not working.
> Here's what I have now:
>
> 
> echo $header; ?>
>
> It writes "Resource id #1" at the top of the page.  What is that?!  :)

Check the manual:

  http://www.php.net/manual/en/function.fopen.php

You're echoing the result of fopen() which is an "int"--you have to make
sure that you're using the function properly ;)

> I have also tried using file().  That displays "Array" on the screen.
What
> am I doing wrong?

I think it's because you're echoing the result of file() which is an array.
You cannot just "echo $the_array;" Try print_r($the_array) and you'll see a
different result--though I doubt it's the one you want to see :)

Check the manual again:

  http://www.php.net/manual/en/function.file.php

Anyway, I think you're looking for something like this:

  http://www.php.net/manual/en/function.file-get-contents.php

Esp. the "User Contributed Notes".

HTH,

- E


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Opening a file to manipulate it

2002-11-16 Thread Justin French
Hi,

on 17/11/02 1:45 PM, Troy May ([EMAIL PROTECTED]) wrote:

>  
> echo $header; ?>
> 
> It writes "Resource id #1" at the top of the page.  What is that?!  :)


You're missing some code -- instead, try this example from the fread() page
in the manual:



Cheers,


Justin French

http://Indent.com.au
Web Developent & 
Graphic Design



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Opening a file to manipulate it

2002-11-16 Thread @ Edwin
Hello,

"Troy May" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Extreme newbie here (halfway through my first book :) ).  I need to open a
> file, read the whole file into a variable, manipulate it, and then echo it
> to the screen.  I'm doing it right from my book and it's not working.
> Here's what I have now:
>
> 
> echo $header; ?>
>
> It writes "Resource id #1" at the top of the page.  What is that?!  :)

Check the manual:

  http://www.php.net/manual/en/function.fopen.php

You're echoing the result of fopen() which is an "int"--you have to make
sure that you're using the function properly ;)

> I have also tried using file().  That displays "Array" on the screen.
What
> am I doing wrong?

I think it's because you're echoing the result of file() which is an array.
You cannot just "echo $the_array;" Try print_r($the_array) and you'll see a
different result--though I doubt it's the one you want to see :)

Check the manual again:

  http://www.php.net/manual/en/function.file.php

Anyway, I think you're looking for something like this:

  http://www.php.net/manual/en/function.file-get-contents.php

Esp. the "User Contributed Notes".

HTH,

- E

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Opening a file to manipulate it

2002-11-16 Thread Troy May
Hello,

Extreme newbie here (halfway through my first book :) ).  I need to open a
file, read the whole file into a variable, manipulate it, and then echo it
to the screen.  I'm doing it right from my book and it's not working.
Here's what I have now:



It writes "Resource id #1" at the top of the page.  What is that?!  :)

I have also tried using file().  That displays "Array" on the screen.  What
am I doing wrong?

Thanks!

Troy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php