Re: [PHP] fgets function for very large files

2009-05-25 Thread shahrzad khorrami
in the following loop:

$row = 1;
while (($line = fgets($handle, 1024)) !== FALSE )
{
$line = str_replace(SEPARATOR, ",", $line);

$data = explode(",", $line);

   $row++;
}

How put 1000 by 1000 lines of csv file to new ones?
and you know I think this works slowly
what do you recommend?

Thanks in advance,
shahrzad





>>
>>
> 1: http://php.net/fgetcsv
> 2: if( ($row % 1) == 0 ) {
> 3: http://php.net/fputcsv
>
>
>


Re: [PHP] fgets function for very large files

2009-05-24 Thread Lars Torben Wilson
2009/5/24 shahrzad khorrami :
> :-o
> I want to divide this large csv file with programming to small one!

If you're on *nix:

% man split


Regards,

Torben

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



Re: [PHP] fgets function for very large files

2009-05-24 Thread Nathan Rixham

shahrzad khorrami wrote:

:-o
I want to divide this large csv file with programming to small one!



1: http://php.net/fgetcsv
2: if( ($row % 1) == 0 ) {
3: http://php.net/fputcsv

csv split in to multiple csv's of 10k rows each

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



Re: [PHP] fgets function for very large files

2009-05-24 Thread shahrzad khorrami
:-o
I want to divide this large csv file with programming to small one!


Re: [PHP] fgets function for very large files

2009-05-24 Thread kranthi
1. open that in a text editor
2. copy a few lines
3. create a new text file
4. paste the copied lines
5. save with the extension .csv

but i doubt this process works i faced exactly same problem few months
back and i found
http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/
to be the best solution

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



Re: [PHP] fgets function for very large files

2009-05-24 Thread shahrzad khorrami
How to divide a large csv file to small ones?

Thanks,
Shahrzad


Re: [PHP] fgets function for very large files

2009-05-23 Thread kranthi
i accept the fact that PMA is full of security holes, and it should
not be used on production server.
but it does not mean that we can never use it on a development server
probably you may have a bit of trouble while moving from development
server to production server. but u can always export your database to
an .sql file and import it into production server...
but if u dont have access to mysql command line(which is the case in
nearly all of the projects i worked on), PMA  will probably be the
only option...(unless u want to rewrite the entire PMA code.)

and certainly 
http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/
is best option for file with > 5000 lines..(but you may hav to prefer
PMA if mysql is not in your PATH env var)

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



Re: [PHP] fgets function for very large files

2009-05-23 Thread Ashley Sheridan
On Sat, 2009-05-23 at 02:59 -0400, Eddie Drapkin wrote:
> On Sat, May 23, 2009 at 2:58 AM, Ashley Sheridan
> wrote:
> 
> >
> > If it's a CSV, I'd recommend using phpMyAdmin directly to import it into
> > the database, assuming you are using a MySQL database that is. It's
> > using tried and tested code for large files like that.
> >
> >
> Tried and true to be what, exactly? Full of security holes and exploits and
> promoting bad habits?
> 
> Really, if all you need to do for the database is import hte .csv, import it
> directly into mysql, from mysql:
> 
> http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/
> 
> And on a related note, you should never, ever use PMA on a production
> machine as it's so easy to exploit and hack.  Furthermore, if you use it on
> your dev server, you'll get used to managing your database with it and have
> trouble using it on the production server.  Take the time to use a real DB
> administration app (like SQLyog of the one that comes with KDE) or an IDE
> with integrated SQL management (like PDT or Zend Studio or Aptana I think
> too).
> 
> Bottom line is if you said you used PMA in an interview I had any say in,
> I'd never hire you and I'd never work with a developer who was that
> uncomfortable with SQL.
I guess I don't get the job then! :p


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] fgets function for very large files

2009-05-23 Thread Michael A. Peters

shahrzad khorrami wrote:

one thing!  I need four fields of  7 fields in each line,
in my code from original csv file first four of fields choose(mappping these
fields with columns of table in db)
for example:
a line in csv file:
"a","b","c","d","e","f","g"

in table of database 4 column : name,ext,tel,date
that 4 field of csv file must map to these column

then I can't directly import my csv file into db. some process must do to
insert  just my selected fields of csv file...


use awk to read the file and create a .sql file with the specified 
fields you want.


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



Re: [PHP] fgets function for very large files

2009-05-23 Thread shahrzad khorrami
one thing!  I need four fields of  7 fields in each line,
in my code from original csv file first four of fields choose(mappping these
fields with columns of table in db)
for example:
a line in csv file:
"a","b","c","d","e","f","g"

in table of database 4 column : name,ext,tel,date
that 4 field of csv file must map to these column

then I can't directly import my csv file into db. some process must do to
insert  just my selected fields of csv file...

Thanks,
Shahrzad


Re: [PHP] fgets function for very large files

2009-05-23 Thread shahrzad khorrami
Thanks for repply :)

It must be automatically, it means that there is a form that an operator
browse a csv with large size(more than 2-3 GB)
and in next step(page) first 1000 line insert into db then by clicking on
next button, next 1000 line
operator don't know any thing about phpmyadmin and programming just browse
the csv file and everything will do automatically
in my code all of lines inserted correctly with @set_time_limit(600) but
it's too slow and bad way...
no use of phpmyadmin and any splitter csv installer program..

Thanks,
shahrzad


Re: [PHP] fgets function for very large files

2009-05-23 Thread Eddie Drapkin
On Sat, May 23, 2009 at 2:58 AM, Ashley Sheridan
wrote:

>
> If it's a CSV, I'd recommend using phpMyAdmin directly to import it into
> the database, assuming you are using a MySQL database that is. It's
> using tried and tested code for large files like that.
>
>
Tried and true to be what, exactly? Full of security holes and exploits and
promoting bad habits?

Really, if all you need to do for the database is import hte .csv, import it
directly into mysql, from mysql:

http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/

And on a related note, you should never, ever use PMA on a production
machine as it's so easy to exploit and hack.  Furthermore, if you use it on
your dev server, you'll get used to managing your database with it and have
trouble using it on the production server.  Take the time to use a real DB
administration app (like SQLyog of the one that comes with KDE) or an IDE
with integrated SQL management (like PDT or Zend Studio or Aptana I think
too).

Bottom line is if you said you used PMA in an interview I had any say in,
I'd never hire you and I'd never work with a developer who was that
uncomfortable with SQL.


Re: [PHP] fgets function for very large files

2009-05-22 Thread Ashley Sheridan
On Sat, 2009-05-23 at 10:41 +0430, shahrzad khorrami wrote:
> hi all,
> 
> I have a csv file with more than 100,000 lines. I want to insert each line
> as a record in a
> database. but for the reason of very number of lines,
> I put a button with caption Next,  when we click on it, 1000 line will
> insert into db and then again click next button
> and insert next 1000 line and
>  is this good way? what do you recommend? and how can I do that?
> 
> 
> Thanks in advance,
> shahrzad

If it's a CSV, I'd recommend using phpMyAdmin directly to import it into
the database, assuming you are using a MySQL database that is. It's
using tried and tested code for large files like that.


Ash
www.ashleysheridan.co.uk


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



[PHP] fgets function for very large files

2009-05-22 Thread shahrzad khorrami
hi all,

I have a csv file with more than 100,000 lines. I want to insert each line
as a record in a
database. but for the reason of very number of lines,
I put a button with caption Next,  when we click on it, 1000 line will
insert into db and then again click next button
and insert next 1000 line and
 is this good way? what do you recommend? and how can I do that?


Thanks in advance,
shahrzad


Re: [PHP] fgets???

2008-02-14 Thread Richard Lynch
On Fri, February 8, 2008 11:54 am, Zoltán Németh wrote:
> 2008. 02. 8, péntek keltezéssel 12.46-kor Daniel Brown ezt írta:
>> On Feb 8, 2008 12:35 PM, Richard Lynch <[EMAIL PROTECTED]> wrote:
>>
>> I knew it.   After silence, Lynch comes back with a vengeance
>> three hours before the week's stats come out.
>>
>> And not only that he top-posts.  ;-P
>
> Wait, this might not be the real Lynch, but his new AI instead, not
> programmed yet for bottom posting :)

I top post when:

The ordering is already so screwed up as to be pointless to not top
post, or
I'm in a super hurry and have only a tiny thing to add to a rather
long post, or
.
.
.

I've had much longer silences on this list.

And even longer stretches of posting WAY too much on a daily basis.

ymmv
ianal
naiaa

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] fgets???

2008-02-08 Thread Zoltán Németh
2008. 02. 8, péntek keltezéssel 12.46-kor Daniel Brown ezt írta:
> On Feb 8, 2008 12:35 PM, Richard Lynch <[EMAIL PROTECTED]> wrote:
> 
> I knew it.   After silence, Lynch comes back with a vengeance
> three hours before the week's stats come out.
> 
> And not only that he top-posts.  ;-P

Wait, this might not be the real Lynch, but his new AI instead, not
programmed yet for bottom posting :)

greets
Zoltán Németh

> 
> -- 
> 
> 
> Daniel P. Brown
> Senior Unix Geek
> 
> 

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



Re: [PHP] fgets???

2008-02-08 Thread Daniel Brown
On Feb 8, 2008 12:35 PM, Richard Lynch <[EMAIL PROTECTED]> wrote:

I knew it.   After silence, Lynch comes back with a vengeance
three hours before the week's stats come out.

And not only that he top-posts.  ;-P

-- 


Daniel P. Brown
Senior Unix Geek


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



Re: [PHP] fgets???

2008-02-08 Thread Richard Lynch
The first possible issue is that the "newline" character[s] is
different for Mac, Windows, and Linux...

So if your file is one format, and fgets is expecting the other, it
won't do what you want.

The next is that if your code is wrong, and is showing it all as one
line, it PROBABLY means you are using a browser, and you PROBABLY
aren't using nl2br to change the newlines (assuming again that nl2br
looks for the right OS newline).  Another option is "View Source" in
the browser to see the newlines.

On Fri, February 8, 2008 11:11 am, Pastor Steve wrote:
> I think I may have written the question wrong. I only want to display
> the
> first line. It is a news story with a headline. I only want to display
> the
> headline in the link.
>
> The output I want is:
>
> The
>
> But I am getting:
>
> The file looks like this.
>
> Does that make more sense?
>
> Thanks,
>
> --
> Steve M.
>
> on 2/8/08 11:03 AM Zoltán Németh ([EMAIL PROTECTED]) wrote:
>
>> 2008. 02. 8, péntek keltezéssel 10.54-kor Pastor Steve ezt írta:
>>> > Is it possible to read each line of data from a file?
>>> >
>>> > I have a text file that has several lines on it. I only want to
>>> display the
>>> > first line only.
>>> >
>>> > The
>>> > file I have
>>> > looks like this.
>>> >
>>> > But outputs:
>>> >
>>> > "The file I have looks like this."
>>
>> you need nl2br()
>> http://hu.php.net/nl2br
>>
>> greets
>> Zoltán Németh
>>
>>> >
>>> > Here is my code:
>>> >
>>> > >> >
>>> >
>>> >
>>> > $dir = "path/to/files/";
>>> >
>>> > // set pattern
>>> > $pattern = ".txt*|.TXT*";
>>> >
>>> > // open directory and parse file list
>>> > if (is_dir($dir))
>>> > {
>>> > if ($dh = opendir($dir))
>>> > {
>>> >
>>> > echo ">> Roman, Times,
>>> > serif; font-size: 12px; width: 290px;\">
>>> > >> padding: 3px;\">
>>> > Breaking News
>>> > Please check here often for breaking news stories.
>>> > 
>>> > 
>>> > 
>>> > ";
>>> >
>>> > // iterate over file list
>>> > while (($filename = readdir($dh)) !== false)
>>> > {
>>> > // if filename matches search pattern, print it
>>> > if (ereg($pattern, $filename))
>>> >if(strpos($filename,'.')>0)
>>> >
>>> > //  if ($filename = str_replace('.html','',$filename))
>>> >
>>> > {
>>> > $fh = fopen($dir . $filename, 'r');
>>> > $filehead = fread($fh, 72);
>>> > fclose($fh);
>>> > echo ">> > href=\"/breaking_news/$filename\">".$filehead."";
>>> > }
>>> > }
>>> > echo "
>>> > 
>>> > ";
>>> >
>>> > // close directory
>>> > closedir($dh);
>>> > }
>>> > }
>>> >
>>> > ?>
>>> >
>>
>
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] fgets???

2008-02-08 Thread Nirmalya Lahiri

--- Daniel Brown <[EMAIL PROTECTED]> wrote:

> On Feb 8, 2008 12:11 PM, Pastor Steve <[EMAIL PROTECTED]>
> wrote:
> > I think I may have written the question wrong. I only want to
> display the
> > first line. It is a news story with a headline. I only want to
> display the
> > headline in the link.
> >
> > The output I want is:
> >
> > The
> >
> > But I am getting:
> >
> > The file looks like this.
> >
> > Does that make more sense?
> 
>  $handle = fopen($filename);
> $data = fgets($handle);
> echo $data."\n";
> ?>
> 
> So long as you don't do a while() loop or something similar,
> fgets() will only read the first line.
> 
> -- 
> 
> 
> Daniel P. Brown
> Senior Unix Geek
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


Another method
 



---
Nirmalya Lahiri
[+91-9433113536]


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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



Re: [PHP] fgets???

2008-02-08 Thread Daniel Brown
On Feb 8, 2008 12:19 PM, Zoltán Németh <[EMAIL PROTECTED]> wrote:
> 2008. 02. 8, péntek keltezéssel 12.17-kor Daniel Brown ezt írta:
> > On Feb 8, 2008 12:11 PM, Pastor Steve <[EMAIL PROTECTED]> wrote:
> > > I think I may have written the question wrong. I only want to display the
> > > first line. It is a news story with a headline. I only want to display the
> > > headline in the link.
> > >
> > > The output I want is:
> > >
> > > The
> > >
> > > But I am getting:
> > >
> > > The file looks like this.
> > >
> > > Does that make more sense?
> >
> >  > $handle = fopen($filename);
> > $data = fgets($handle);
> > echo $data."\n";
> > ?>
> >
> > So long as you don't do a while() loop or something similar,
> > fgets() will only read the first line.
>
> sure, and much more efficient than my last letter, so ignore that...
> its friday, and late, and I'm still at work, so my mind is not on the
> top now... :)

Zoltan, if you're sticking around, zip me a message off-list.  I
have a favor to ask of you.

-- 


Daniel P. Brown
Senior Unix Geek


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



Re: [PHP] fgets???

2008-02-08 Thread Zoltán Németh
2008. 02. 8, péntek keltezéssel 12.17-kor Daniel Brown ezt írta:
> On Feb 8, 2008 12:11 PM, Pastor Steve <[EMAIL PROTECTED]> wrote:
> > I think I may have written the question wrong. I only want to display the
> > first line. It is a news story with a headline. I only want to display the
> > headline in the link.
> >
> > The output I want is:
> >
> > The
> >
> > But I am getting:
> >
> > The file looks like this.
> >
> > Does that make more sense?
> 
>  $handle = fopen($filename);
> $data = fgets($handle);
> echo $data."\n";
> ?>
> 
> So long as you don't do a while() loop or something similar,
> fgets() will only read the first line.

sure, and much more efficient than my last letter, so ignore that...
its friday, and late, and I'm still at work, so my mind is not on the
top now... :)

greets
Zoltán Németh

> 

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



Re: [PHP] fgets???

2008-02-08 Thread Zoltán Németh
2008. 02. 8, péntek keltezéssel 11.11-kor Pastor Steve ezt írta:
> I think I may have written the question wrong. I only want to display
> the first line. It is a news story with a headline. I only want to
> display the headline in the link.
> 
> The output I want is:
> 
> The
> 
> But I am getting:
> 
> The file looks like this.
> 
> Does that make more sense?

in that case why not read the file as an array of lines and display the
first line?
$f = file('whatever.txt');
echo $f[0];

http://hu.php.net/file

greets
Zoltán Németh

> 
> Thanks,
> 
> --
> Steve M.
> 
> on 2/8/08 11:03 AM Zoltán Németh ([EMAIL PROTECTED]) wrote:
> 
> 2008. 02. 8, péntek keltezéssel 10.54-kor Pastor Steve ezt
> írta:
> > Is it possible to read each line of data from a file?
> > 
> > I have a text file that has several lines on it. I only want
> to display the
> > first line only.
> > 
> > The 
> > file I have 
> > looks like this.
> > 
> > But outputs:
> > 
> > "The file I have looks like this."
> 
> you need nl2br()
> http://hu.php.net/nl2br
> 
> greets
> Zoltán Németh
> 
> > 
> > Here is my code:
> > 
> >  > 
> > 
> > 
> > $dir = "path/to/files/";
> > 
> > // set pattern
> > $pattern = ".txt*|.TXT*";
> > 
> > // open directory and parse file list
> > if (is_dir($dir))
> > {
> > if ($dh = opendir($dir))
> > {
> > 
> > echo " Roman, Times,
> > serif; font-size: 12px; width: 290px;\">
> >  padding: 3px;\">
> > Breaking News
> > Please check here often for breaking news
> stories.
> > 
> > 
> > 
> > ";
> > 
> > // iterate over file list
> > while (($filename = readdir($dh)) !== false)
> > {
> > // if filename matches search pattern, print it
> > if (ereg($pattern, $filename))
> >if(strpos($filename,'.')>0)
> >
> > //  if ($filename = str_replace('.html','',$filename))
> > 
> > {
> > $fh = fopen($dir . $filename, 'r');
> > $filehead = fread($fh, 72);
> > fclose($fh);
> > echo " > href=\"/breaking_news/$filename\">".$filehead."";
> > }
> > }
> > echo "
> > 
> > ";
> > 
> > // close directory
> > closedir($dh);
> > }
> > }
> > 
> > ?>
> > 
> 
> 

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



Re: [PHP] fgets???

2008-02-08 Thread Daniel Brown
On Feb 8, 2008 12:11 PM, Pastor Steve <[EMAIL PROTECTED]> wrote:
> I think I may have written the question wrong. I only want to display the
> first line. It is a news story with a headline. I only want to display the
> headline in the link.
>
> The output I want is:
>
> The
>
> But I am getting:
>
> The file looks like this.
>
> Does that make more sense?



So long as you don't do a while() loop or something similar,
fgets() will only read the first line.

-- 


Daniel P. Brown
Senior Unix Geek


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



Re: [PHP] fgets???

2008-02-08 Thread Pastor Steve
I think I may have written the question wrong. I only want to display the
first line. It is a news story with a headline. I only want to display the
headline in the link.

The output I want is:

The

But I am getting:

The file looks like this.

Does that make more sense?

Thanks,

--
Steve M.

on 2/8/08 11:03 AM Zoltán Németh ([EMAIL PROTECTED]) wrote:

> 2008. 02. 8, péntek keltezéssel 10.54-kor Pastor Steve ezt írta:
>> > Is it possible to read each line of data from a file?
>> > 
>> > I have a text file that has several lines on it. I only want to display the
>> > first line only.
>> > 
>> > The 
>> > file I have 
>> > looks like this.
>> > 
>> > But outputs:
>> > 
>> > "The file I have looks like this."
> 
> you need nl2br()
> http://hu.php.net/nl2br
> 
> greets
> Zoltán Németh
> 
>> > 
>> > Here is my code:
>> > 
>> > > > 
>> > 
>> > 
>> > $dir = "path/to/files/";
>> > 
>> > // set pattern
>> > $pattern = ".txt*|.TXT*";
>> > 
>> > // open directory and parse file list
>> > if (is_dir($dir))
>> > {
>> > if ($dh = opendir($dir))
>> > {
>> > 
>> > echo "> > serif; font-size: 12px; width: 290px;\">
>> > 
>> > Breaking News
>> > Please check here often for breaking news stories.
>> > 
>> > 
>> > 
>> > ";
>> > 
>> > // iterate over file list
>> > while (($filename = readdir($dh)) !== false)
>> > {
>> > // if filename matches search pattern, print it
>> > if (ereg($pattern, $filename))
>> >if(strpos($filename,'.')>0)
>> >
>> > //  if ($filename = str_replace('.html','',$filename))
>> > 
>> > {
>> > $fh = fopen($dir . $filename, 'r');
>> > $filehead = fread($fh, 72);
>> > fclose($fh);
>> > echo "> > href=\"/breaking_news/$filename\">".$filehead."";
>> > }
>> > }
>> > echo "
>> > 
>> > ";
>> > 
>> > // close directory
>> > closedir($dh);
>> > }
>> > }
>> > 
>> > ?>
>> > 
> 




Re: [PHP] fgets???

2008-02-08 Thread Zoltán Németh
2008. 02. 8, péntek keltezéssel 10.54-kor Pastor Steve ezt írta:
> Is it possible to read each line of data from a file?
> 
> I have a text file that has several lines on it. I only want to display the
> first line only.
> 
> The 
> file I have 
> looks like this.
> 
> But outputs:
> 
> "The file I have looks like this."

you need nl2br()
http://hu.php.net/nl2br

greets
Zoltán Németh

> 
> Here is my code:
> 
>  
> 
> 
> $dir = "path/to/files/";
> 
> // set pattern
> $pattern = ".txt*|.TXT*";
> 
> // open directory and parse file list
> if (is_dir($dir))
> {
> if ($dh = opendir($dir))
> {
> 
> echo " serif; font-size: 12px; width: 290px;\">
> 
> Breaking News
> Please check here often for breaking news stories.
> 
> 
> 
> ";
> 
> // iterate over file list
> while (($filename = readdir($dh)) !== false)
> {
> // if filename matches search pattern, print it
> if (ereg($pattern, $filename))
>if(strpos($filename,'.')>0)
>
> //  if ($filename = str_replace('.html','',$filename))
> 
> {
> $fh = fopen($dir . $filename, 'r');
> $filehead = fread($fh, 72);
> fclose($fh);
> echo " href=\"/breaking_news/$filename\">".$filehead."";
> }
> }
> echo "
> 
> ";
> 
> // close directory
> closedir($dh);
> }
> }
> 
> ?>
> 

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



[PHP] fgets???

2008-02-08 Thread Pastor Steve
Is it possible to read each line of data from a file?

I have a text file that has several lines on it. I only want to display the
first line only.

The 
file I have 
looks like this.

But outputs:

"The file I have looks like this."

Here is my code:



Breaking News
Please check here often for breaking news stories.



";

// iterate over file list
while (($filename = readdir($dh)) !== false)
{
// if filename matches search pattern, print it
if (ereg($pattern, $filename))
   if(strpos($filename,'.')>0)
   
//  if ($filename = str_replace('.html','',$filename))

{
$fh = fopen($dir . $filename, 'r');
$filehead = fread($fh, 72);
fclose($fh);
echo "".$filehead."";
}
}
echo "

";

// close directory
closedir($dh);
}
}

?>

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



[PHP] fgets fails after fopen succeeds -- cleaned up for better digestion.

2005-05-12 Thread Thomas Powell
I removed the "r+", since that not my intended mode.
File Handle is 1 after the fopen call.
fgets, feof, and fclose fail on $fh. (So does fread, FWIW).
The file exists. fopen fails if it is moved.
 *Code:*


 0) {
print '' . $line ."\n";
}
}
?>


 *Output:*
./outside/index.txt 

   File Handle:1
   *Warning*: fgets(): supplied argument is not a valid stream resource 
   in *C:\Program Files\Apache 
   Group\Apache2\htdocs\youmightbe\outside.php* on line *12*
   
   *Warning*: feof(): supplied argument is not a valid stream resource in 
   *C:\Program Files\Apache Group\Apache2\htdocs\youmightbe\outside.php*on line 
   *12*
   

*Warning*: fclose(): supplied argument is not a valid stream resource
in *C:\Program
Files\Apache Group\Apache2\htdocs\youmightbe\outside.php* on line *22*
**


Re: [PHP] fgets fails after fopen succeeds

2005-05-10 Thread Richard Lynch
On Tue, May 10, 2005 7:42 pm, Thomas Powell said:
> Printing $fh printed a 1.
>
> My original file mode was just "r", I changed to "r+" to see if I'd get
> permissions problems. The file handle seems to be fine. fgets just doesn't
> like it.
>
> This is an adaptation of the following code, which works fine on another
> Windows 2000/Apache setup. Irony is, the original code doesn't work when
> ported. I think I'm missing something in setup or permissions.

Hrmph.

God only knows what Windows 2K might have done with its file permissions
system (or lack thereof)...

What are the permissions settings on the files that work versus those that
don't?

Just for fun, if fgets doesn't like it, does fread like it?

Remote, but distinct, possibility:  Bad hardware.

If the underlying hard drive is kerfraggled, then you *could* see the
behaviour you're getting -- The file seems to open okay, but an attempt to
actually read data conks out on a bad sector.

Can you skip the fgets section ENTIRELY and just fclose() it?  Once the
handle is known to be corrupt (by a bad sector) then fclose() will
probably die, but if you don't attempt to read a bad sector, fclose()
shouldn't have much to do, and should succeed.

Certainly doing a backup and running a disk check wouldn't hurt, to
eliminate the hardware possibility.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] fgets fails after fopen succeeds

2005-05-10 Thread Richard Lynch
On Tue, May 10, 2005 1:34 pm, Thomas Powell said:
> Summary:
> fopen returns a file handle, yet fgets doesn't want to read it. I've
> scoured
> google, php.net , phpfreaks, usenet, etc. It seems to work
> elsewhere.
>
> My setup:
> Apache 2.0.47
> PHP/5.0.4
> Windows 2000
>
> The call:
> make_link_list("index");
>
> (the file exists for fopen(), and actually errors if I add characters to
> break it)
>
> My Source Code:
>
>  function make_link_list($name="") {
>
> print $_SERVER['DOCUMENT_ROOT'].'/outside/'.$name.'.txt';
> ?>
> 
>  $fh=fopen($_SERVER['DOCUMENT_ROOT'].'/outside/'.$name.'.txt', 'r+') ||
> die("Cannot open file");

I don't think you want || here -- The operator precedence of = and || and
OR are what's biting you in the butt, almost for sure.

echo "fh is $fh\n";

If that doesn't print out "Resource #1" (or some other number) then you've
got it wrong, and you might as well ignore the rest of this script until
it's right.

Also, it's probably REALLY BAD SECURITY that the PHP user can write (r+) a
file inside your DOCUMENT_ROOT!!!

Move the file somewhere else, outside the web tree, and give yourself a
config file to set the path for easy changing/installing.


> for ($line = fgets($fh, 1000); 0 && ! feof($fh); $line = fgets($fh)) {

Dunno what the 0 && is about, but it don't belong there when you're done,
of course...

>  $line = trim($line);
>  if(strlen($line) > 0) {
>  print '' . $line ."\n";
>  }
> }
> ?>
> 
>  fclose($fh);
> }
> ?
>
> Output:
> C:/Program Files/Apache Group/Apache2/htdocs/youmightbe/outside/index.txt
>
>
>*Warning*: fgets(): supplied argument is not a valid stream resource
>in *C:\Program Files\Apache
>Group\Apache2\htdocs\youmightbe\outside.php* on line *11*
>
>
> *Warning*: fclose(): supplied argument is not a valid stream resource
> in *C:\Program
> Files\Apache Group\Apache2\htdocs\youmightbe\outside.php* on line *20*
>


-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] fgets fails after fopen succeeds

2005-05-10 Thread Thomas Powell
Printing $fh printed a 1.

My original file mode was just "r", I changed to "r+" to see if I'd get 
permissions problems. The file handle seems to be fine. fgets just doesn't 
like it.

The 0 && !feof() was a "commenting out" of the for loop to prevent the fgets 
from running so that I so print the $fh.

This is an adaptation of the following code, which works fine on another 
Windows 2000/Apache setup. Irony is, the original code doesn't work when 
ported. I think I'm missing something in setup or permissions.



 0) {
print '' . $line ."\n";
}
}
?>




[PHP] fgets fails after fopen succeeds

2005-05-10 Thread Thomas Powell
Summary:
fopen returns a file handle, yet fgets doesn't want to read it. I've scoured 
google, php.net , phpfreaks, usenet, etc. It seems to work 
elsewhere.

My setup:
Apache 2.0.47
PHP/5.0.4
Windows 2000

The call:
make_link_list("index");

(the file exists for fopen(), and actually errors if I add characters to 
break it)

My Source Code:



 0) {
 print '' . $line ."\n";
 }
}
?>



Re: [PHP] fgets prob... !?

2003-09-29 Thread Marek Kilimajer
I don't think php just comes and changes your output. Check the source 
html output if it is realy only one #.

mArK wrote:

H!

I have this segment of script...

...
$resp = fgets( $sock, 512 );
echo $resp;
...
the output must be:
[EMAIL PROTECTED]
but here came php and take the 3 "#" and convert
they in only one "#", and the output currently is:
[EMAIL PROTECTED]

How I say to php: "STOP", leave my "#" in peace?
--

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


[PHP] fgets prob... !?

2003-09-28 Thread mArK
H!

I have this segment of script...

...
$resp = fgets( $sock, 512 );
echo $resp;
...

the output must be:
[EMAIL PROTECTED]

but here came php and take the 3 "#" and convert
they in only one "#", and the output currently is:

[EMAIL PROTECTED]

How I say to php: "STOP", leave my "#" in peace?
--

mArk

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



Re: [PHP] fgets() problem

2003-06-13 Thread Marek Kilimajer
From the manual:
Note:  The length parameter became optional in PHP 4.2.0, if omitted, it 
would assume 1024 as the line length. As of PHP 4.3, omitting length 
will keep reading from the stream until it reaches the end of the line. 
If the majority of the lines in the file are all larger than 8KB, it is 
more resource efficient for your script to specify the maximum line length.

Armand Turpel wrote:
It seems that some php versions have difficulties with the fgets() function.

On php 4.3.2 it works fine, but other versions report warnings.

fgets($f);
Warning: Wrong parameter count for fgets() in
/var/www/Xprotector/include/base.inc.php on line 70


If I change fgets to

fgets($f, 4096);

it woks.

Any idea why?






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


[PHP] fgets() problem

2003-06-13 Thread Armand Turpel
It seems that some php versions have difficulties with the fgets() function.

On php 4.3.2 it works fine, but other versions report warnings.

fgets($f);
Warning: Wrong parameter count for fgets() in
/var/www/Xprotector/include/base.inc.php on line 70



If I change fgets to

fgets($f, 4096);

it woks.


Any idea why?




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



Re: [PHP] fgets and Macs

2003-01-15 Thread Chris Shiflett
--- Jason Jacobs <[EMAIL PROTECTED]> wrote:
> It would be wonderful if my php.ini file actually
> contained the variable "auto_detect_line_endings."
>  How can I solve this problem?

Try adding it yourself. Don't let its absence dissuade you
from giving it a shot. :-)

Chris

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




[PHP] fgets and Macs

2003-01-15 Thread Jason Jacobs
Hello all.  I was doing some reading and found that fgets() doesn't work so well with 
a text file created on a mac, and php.net has a fix.  It would be wonderful if my 
php.ini file actually contained the variable "auto_detect_line_endings."  How can I 
solve this problem?  Is my only solution (without upgrading php) to convert the text 
files to unix format?  Or am I looking in the wrong place for that value?  Thanks for 
your help.

-
Jason Jacobs

Support a Constitutional Amendment to protect the Pledge of Allegiance and National 
Motto. Go to www.wepledge.com


Re: [PHP] fgets() question?

2002-12-22 Thread Jason Wong
On Sunday 22 December 2002 14:18, Noel Wade wrote:
> Okay, attacking my flat-file issues from the other end:
>
> When you use $foo = fgets($fp_file);  it appears that a blank line ends up
> looking exactly like a FALSE ("failed to read") return value...  Is there
> any way to differentiate between an empty-string read (a blank line in a
> flat-file) and a FALSE return from fgets() ??

Your code is probably incorrect. Does the example for fgets() in the manual 
work for you?

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
I'm proud to be paying taxes in the United States.  The only thing is
-- I could be just as proud for half the money.
-- Arthur Godfrey
*/


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




[PHP] fgets() question?

2002-12-21 Thread Noel Wade
Okay, attacking my flat-file issues from the other end:

When you use $foo = fgets($fp_file);  it appears that a blank line ends up
looking exactly like a FALSE ("failed to read") return value...  Is there
any way to differentiate between an empty-string read (a blank line in a
flat-file) and a FALSE return from fgets() ??

Thanks a bunch,

--Noel




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




[PHP] fgets()

2002-11-03 Thread Khalid El-Kary
hi,
i want to open a remote file using fopen() i tried both of these ways

$filename="http://www.domain.com/filename.txt";;
$file=fopen($filename,"r");
$filecontents=fread($file,filesize($filename));

this one didn't work because it's apparent that the file isn't in the local 
file system so filesize($filename) won't work ...

the second way was this:

$filename="http://www.domain.com/filename.txt";;
$file=fopen($filename,"r");
$filecontents="";
while (!feof($file))
{
 $filecontents.=fgets($file);
}

this one worked well with PHP4.2.3 but with versions under PHP 4.2.0 it 
didn't work

So what else can i try to just get the whole contents of the file into a 
string?

thanx
khalid


_
Internet access plans that fit your lifestyle -- join MSN. 
http://resourcecenter.msn.com/access/plans/default.asp


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



Re: [PHP] fgets question

2002-08-14 Thread Monte Ohrt

I don't have the option of editing the text files to work right. I want 
to be able to read an arbitrary text file line by line and process each 
one. So I suppose I could do this (?)



DL Neil wrote:
> Hi Monte,
> 
> 
>>Hi, I have a question about fgets(), it seems to pick up an extra line
>>at the end of a text file.
> 
> ...
> 
>>8\n
> 
> ...
> 
>>Here is the output (showing newlines as \n):
>>buffer is 1\n
>>buffer is 2\n
>>buffer is 3\n
>>buffer is 4\n
>>buffer is 5\n
>>buffer is 6\n
>>buffer is 7\n
>>buffer is 8\n
>>buffer is
>>My question, why is there an extra line? Or in other words, how do I get
>>this to loop exactly 8 times if there are only 8 lines?
> 
> 
> 
> The answer is that there isn't an 'extra' line, there are as many as you
> put/PHP reads!
> The question to ask is: how does a stream file end?
> Answer: with an EOF character (not an LF).
> 
> Lines in a (*nix) stream file are separated by LF or \n character, therefore
> there is a ninth 'line' (of absolutely nothing) between the last LF and the
> EOF. Take out that last \n and things should work the way you want.
> 
> Regards,
> =dn
> 
> 
>


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




Re: [PHP] fgets question

2002-08-14 Thread DL Neil

Hi Monte,

> Hi, I have a question about fgets(), it seems to pick up an extra line
> at the end of a text file.
...
> 8\n
...
> Here is the output (showing newlines as \n):
> buffer is 1\n
> buffer is 2\n
> buffer is 3\n
> buffer is 4\n
> buffer is 5\n
> buffer is 6\n
> buffer is 7\n
> buffer is 8\n
> buffer is
> My question, why is there an extra line? Or in other words, how do I get
> this to loop exactly 8 times if there are only 8 lines?


The answer is that there isn't an 'extra' line, there are as many as you
put/PHP reads!
The question to ask is: how does a stream file end?
Answer: with an EOF character (not an LF).

Lines in a (*nix) stream file are separated by LF or \n character, therefore
there is a ninth 'line' (of absolutely nothing) between the last LF and the
EOF. Take out that last \n and things should work the way you want.

Regards,
=dn




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




RE: [PHP] fgets question

2002-08-14 Thread Jay Blanchard

[snip]
1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A
No extra newlines that I could see.
>>
>>1\n
>>2\n
>>3\n
>>4\n
>>5\n
>>6\n
>>7\n
>>8\n
>>
>>I create this PHP program and run it:
>>
>>>$fd = fopen ("test","r");
>>while (!feof ($fd)) {
>> $buffer = fgets($fd, 4096);
>> echo "buffer is $buffer";
>>}
>>fclose ($fd);
>>?>

The only way that I can see to do this is to test the output before printing
while (!feof ($fd)) {
 $buffer = fgets($fd, 4096);
if($buffer > 0){
  echo "buffer is $buffer";
}
}

Or I suppose you could say if(!$buffer), will make for less code

HTH!

Jay

***
* Texas PHP Developers Conf  Spring 2003  *
* T Bar M Resort & Conference Center  *
* New Braunfels, Texas*
* San Antonio Area PHP Developers Group   *
* Interested? Contact [EMAIL PROTECTED] *
***



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




Re: [PHP] fgets question

2002-08-14 Thread Monte Ohrt

That was my first thought but that wasn't it. To be sure, I urlencoded 
the file and looked at it:

1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A

No extra newlines that I could see.

FYI, if you run the program from the command line, you have to pipe the 
output to a pager or you will not see the last (extra) line since there 
is no newline character.

I'm using PHP 4.2.2 on Solaris sparc.

Monte

Kevin Stone wrote:
> The only explaination is that 'vi' is putting an extra line in there that
> you're not seeing.
> -Kevin
> 
> - Original Message -
> From: "Monte Ohrt" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, August 14, 2002 11:05 AM
> Subject: [PHP] fgets question
> 
> 
> 
>>Hi, I have a question about fgets(), it seems to pick up an extra line
>>at the end of a text file.
>>
>>example, I open a new file named "test" with the vi editor and make it 8
>>lines long like so (showing newlines as \n):
>>
>>1\n
>>2\n
>>3\n
>>4\n
>>5\n
>>6\n
>>7\n
>>8\n
>>
>>I create this PHP program and run it:
>>
>>>$fd = fopen ("test","r");
>>while (!feof ($fd)) {
>> $buffer = fgets($fd, 4096);
>> echo "buffer is $buffer";
>>}
>>fclose ($fd);
>>?>
>>
>>Here is the output (showing newlines as \n):
>>
>>buffer is 1\n
>>buffer is 2\n
>>buffer is 3\n
>>buffer is 4\n
>>buffer is 5\n
>>buffer is 6\n
>>buffer is 7\n
>>buffer is 8\n
>>buffer is
>>
>>
>>My question, why is there an extra line? Or in other words, how do I get
>>this to loop exactly 8 times if there are only 8 lines?
>>
>>TIA
>>Monte
>>
>>
>>--
>>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] fgets question

2002-08-14 Thread Kevin Stone

The only explaination is that 'vi' is putting an extra line in there that
you're not seeing.
-Kevin

- Original Message -
From: "Monte Ohrt" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 14, 2002 11:05 AM
Subject: [PHP] fgets question


> Hi, I have a question about fgets(), it seems to pick up an extra line
> at the end of a text file.
>
> example, I open a new file named "test" with the vi editor and make it 8
> lines long like so (showing newlines as \n):
>
> 1\n
> 2\n
> 3\n
> 4\n
> 5\n
> 6\n
> 7\n
> 8\n
>
> I create this PHP program and run it:
>
>  $fd = fopen ("test","r");
> while (!feof ($fd)) {
>  $buffer = fgets($fd, 4096);
>  echo "buffer is $buffer";
> }
> fclose ($fd);
> ?>
>
> Here is the output (showing newlines as \n):
>
> buffer is 1\n
> buffer is 2\n
> buffer is 3\n
> buffer is 4\n
> buffer is 5\n
> buffer is 6\n
> buffer is 7\n
> buffer is 8\n
> buffer is
>
>
> My question, why is there an extra line? Or in other words, how do I get
> this to loop exactly 8 times if there are only 8 lines?
>
> TIA
> Monte
>
>
> --
> 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




[PHP] fgets question

2002-08-14 Thread Monte Ohrt

Hi, I have a question about fgets(), it seems to pick up an extra line 
at the end of a text file.

example, I open a new file named "test" with the vi editor and make it 8 
lines long like so (showing newlines as \n):

1\n
2\n
3\n
4\n
5\n
6\n
7\n
8\n

I create this PHP program and run it:



Here is the output (showing newlines as \n):

buffer is 1\n
buffer is 2\n
buffer is 3\n
buffer is 4\n
buffer is 5\n
buffer is 6\n
buffer is 7\n
buffer is 8\n
buffer is


My question, why is there an extra line? Or in other words, how do I get 
this to loop exactly 8 times if there are only 8 lines?

TIA
Monte


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




Re: [PHP] php fgets()

2002-05-15 Thread Miguel Cruz

On Wed, 15 May 2002, arnaud gonzales wrote:
> I'm newbie in php and i would like to clearly understand how can i use:
>   LENGTH  in   string fgets ( int fp [, int length])
> 
> "Returns a string of up to length - 1 bytes read from the file pointed to by
> fp. Reading ends when length - 1 bytes have been read, on a newline (which
> is included in the return value), or on EOF (whichever comes first). If no
> length is specified, the length defaults to 1k, or 1024 bytes."
> 
> -Can i have an example of the differents way for reading file with fgets
> according to the  differentes values of "length "?
> -why '4096' is used as length for reading a file line by line ?
> 
>   $fd = fopen ("/tmp/inputfile.txt", "r");
>   while (!feof ($fd)) {
>$buffer = fgets($fd, 4096);
>echo $buffer;
>   }
>   fclose ($fd);
> 
> Is this any max for one line??

The idea is to avoid runaway reads. This way if you get pointed to a file 
that's a link to /dev/random, you won't blow through all your memory and 
explode.

miguel


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




[PHP] php fgets()

2002-05-14 Thread arnaud gonzales

Hi,
I'm newbie in php and i would like to clearly understand how can i use:
  LENGTH  in   string fgets ( int fp [, int length])

"Returns a string of up to length - 1 bytes read from the file pointed to by
fp. Reading ends when length - 1 bytes have been read, on a newline (which
is included in the return value), or on EOF (whichever comes first). If no
length is specified, the length defaults to 1k, or 1024 bytes."

-Can i have an example of the differents way for reading file with fgets
according to thedifferentes values of "length "?
-why '4096' is used as length for reading a file line by line ?

$fd = fopen ("/tmp/inputfile.txt", "r");
while (!feof ($fd)) {
 $buffer = fgets($fd, 4096);
 echo $buffer;
}
fclose ($fd);

Is this any max for one line??

TIA.

arnaud G.


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




Re: [PHP] fgets and eval

2001-12-18 Thread Greg Donald


> Okay here is the situation. I am reading a file using fgets up until I hit
a certain delimiter within the text. No problem there. This text file may or
may not
> contain php in the format . So I now have two variables $header
and $footer which may or may not contain some php within them. I need to
echo
> the variables at the top and bottom of other files but need any php that
may be in there to execute.
>
>  I tried echo(eval($header))
>
> and I also tried
>
> $header = addslashes($header);
> eval("\$header = \"$header\";");
> $header= stripslashes($header);
> echo($header);
>
> The first produces and error, the second produces no error however only
variables evaluate while actual commands, such as echo just get written into
the
> code.
>
> Any idea  what I may be doing wrong here?

Try this, it's from a template parsing function I wrote:

$header = str_replace("\\'","'",addslashes($header));
eval("\$header = \"$header\";");

Greg



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] fgets and eval

2001-12-18 Thread Gerard Onorato

Hello all,

Okay here is the situation. I am reading a file using fgets up until I hit a certain 
delimiter within the text. No problem there. This text file may or may not 
contain php in the format . So I now have two variables $header and $footer 
which may or may not contain some php within them. I need to echo 
the variables at the top and bottom of other files but need any php that may be in 
there to execute.

 I tried echo(eval($header)) 

and I also tried

$header = addslashes($header); 
eval("\$header = \"$header\";"); 
$header= stripslashes($header); 
echo($header); 

The first produces and error, the second produces no error however only variables 
evaluate while actual commands, such as echo just get written into the 
code.

Any idea  what I may be doing wrong here?

Thanks,

Gerard



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] fgets

2001-08-30 Thread Christian Reiniger

On Wednesday 29 August 2001 23:45, Christopher William Wesley wrote:
> On Wed, 29 Aug 2001, Joseph Bannon wrote:
> > I want to use fgets to get an image off the server and then print it.
> > Kinda like if you call the script picture.php, an image will appear.
> > How do I do
>
> I do this, with fopen() and fpassthru() ...
>
> $im = fopen( "myImage.jpg", "r" );
> if( !$im ){
> // FILE WASN'T FOUND
> } else {

// important:
header ("Content-Type: image/jpeg"); // or image/png

> // ALL GOOD - SEND IT TO THE BROWSER
> fpassthru( $im );
>   }
>   fclose( $im );

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

CPU not found. retry, abort, ignore?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] fgets

2001-08-29 Thread Christopher William Wesley

On Wed, 29 Aug 2001, Joseph Bannon wrote:

> I want to use fgets to get an image off the server and then print it. Kinda
> like if you call the script picture.php, an image will appear. How do I do

I do this, with fopen() and fpassthru() ...

$im = fopen( "myImage.jpg", "r" );
if( !$im ){
// FILE WASN'T FOUND
} else {
// ALL GOOD - SEND IT TO THE BROWSER
fpassthru( $im );
}
fclose( $im );

For the sake of simplicity, I left off additional error checking I do ...
but this is the core of the idea.  The image functions
(http://www.php.net/manual/en/ref.image.php) work well too.  When just
pushing out an unmodified image, the above code has proven simplest for
me.

~Chris   /"\
 \ / Pine Ribbon Campaign
Microsoft Security Specialist X  Against Outlook
The moron in Oxymoron.   / \ http://www.thebackrow.net


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] fgets

2001-08-29 Thread Joseph Bannon

I want to use fgets to get an image off the server and then print it. Kinda
like if you call the script picture.php, an image will appear. How do I do
this? I'm trying to create a graphical counter with php.

Joseph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]