php-general Digest 26 Feb 2007 02:16:46 -0000 Issue 4646

Topics (messages 249395 through 249424):

Re: input on sessions vs cookies
        249395 by: Robert Cummings
        249420 by: Tosca
        249421 by: Richard Lynch
        249422 by: Tosca

re-config the language of phpmyadmin
        249396 by: edwardspl.ita.org.mo
        249423 by: Chris

Combining sound files
        249397 by: tedd
        249411 by: Colin Guthrie
        249414 by: tedd
        249415 by: Colin Guthrie

Store and retrieve photo from PostgreSQL
        249398 by: Alain Roger
        249416 by: Chris
        249424 by: Kevin Waterson

Uploading into website directory for Php files
        249399 by: StainOnRug
        249400 by: Joker7
        249401 by: Edward Vermillion

how to display images stored in DB
        249402 by: Alain Roger
        249404 by: zerof
        249406 by: Dave Goodchild
        249407 by: tedd
        249408 by: tedd

indexing with fopen
        249403 by: Miguel Vaz
        249412 by: João Cândido de Souza Neto
        249419 by: Chris

how to retrieve pictures from postgreSQL DB
        249405 by: Alain Roger
        249409 by: tedd
        249410 by: Colin Guthrie

read file local not remote
        249413 by: Joker7
        249418 by: Martin Zvarík

Error handling for Memcached PHP Extension
        249417 by: Cabbar Duzayak

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sat, 2007-02-24 at 20:05 -0800, benifactor wrote:
> as of right now, when the user logs in, i have a cookie storing username...
> then on all of the pages i need data i have it query the database and using
> the cookie data to retrieve user information.. is there a more secure way to
> do this?

This is horrible. It means if I know of any other user on your site and
I think they may be logged in then I can change the username in my
cookie and hijack their session. In fact, if you have any kind of system
that exposes user input (such as a forum) then I can with great accuracy
determine what users are logged in and are active thus making it trivial
to hijack sessions. Instead of storing the username, create a unique ID
(32 alphanumeric digits is common) that maps to the session data. This
is what PHP native sessions do. Why not use PHP native sessions? They've
done most of the work for you and they use cookies when it is detected
that cookies are enabled.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Quote from Fahad Pervaiz <[EMAIL PROTECTED]>:
"To ensure best security use database as well. Store IP, Session ID,
 username, login time. After every few minutes you can re authenticate the
 user against these parameters."

I have a login system with sessions and a database where I store session ID,
username and what kind of user they are (like admin, moderator of regular
member). This I check every time a page is refreshed. Is this secure enough?

--- End Message ---
--- Begin Message ---
On Sun, February 25, 2007 6:45 pm, Tosca wrote:
> Quote from Fahad Pervaiz <[EMAIL PROTECTED]>:
> "To ensure best security use database as well. Store IP, Session ID,
>   username, login time. After every few minutes you can re
> authenticate the
>   user against these parameters."
>
> I have a login system with sessions and a database where I store
> session ID,
> username and what kind of user they are (like admin, moderator of
> regular
> member). This I check every time a page is refreshed. Is this secure
> enough?

Are you running a bank?
Or is it just a community forum?

Without context, nobody on earth can answer this.

Start reading here:
http://phpsec.org
to have a better handle on PHP security.

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

--- End Message ---
--- Begin Message ---
It's a website where you can reply to news, blogs and other messages and
with a forum.

On 2/26/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Sun, February 25, 2007 6:45 pm, Tosca wrote:
> Quote from Fahad Pervaiz <[EMAIL PROTECTED]>:
> "To ensure best security use database as well. Store IP, Session ID,
>   username, login time. After every few minutes you can re
> authenticate the
>   user against these parameters."
>
> I have a login system with sessions and a database where I store
> session ID,
> username and what kind of user they are (like admin, moderator of
> regular
> member). This I check every time a page is refreshed. Is this secure
> enough?

Are you running a bank?
Or is it just a community forum?

Without context, nobody on earth can answer this.

Start reading here:
http://phpsec.org
to have a better handle on PHP security.

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



--- End Message ---
--- Begin Message ---
Dear All,

How to config ( hard code ) the phpmyadmin of language to "Chinese Charactor Set" ?
eg : Big5

Edward.

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
Dear All,

How to config ( hard code ) the phpmyadmin of language to "Chinese Charactor Set" ?
eg : Big5

Why don't you ask them? http://sourceforge.net/projects/phpmyadmin/

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hi gang:

I can combine two mp3 sound files together by simply:

// load  first

$file = "a.mp3";
$handle = fopen($file, "rb");
$size = filesize($file);
$load = fread($handle, $size);
fclose($handle);

// load second

$file = "b.mp3";
$handle = fopen($file, "rb");
$size = filesize($file);
$load .= fread($handle, $size);
fclose($handle);

// save both as one audio file

$filename = "tmp/a.mp3";
$file = fopen( $filename, "wb" );
fwrite( $file, $load);
fclose( $file );

However, I can't do the same with .WAV files. Does anyone know a way to combine .WAV files similar to the way shown above?

Thanks.

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
> Hi gang:
> 
> I can combine two mp3 sound files together by simply:
> 
> // load  first
> 
> $file = "a.mp3";
> $handle = fopen($file, "rb");
> $size = filesize($file);
> $load = fread($handle, $size);
> fclose($handle);
> 
> // load second
> 
> $file = "b.mp3";
> $handle = fopen($file, "rb");
> $size = filesize($file);
> $load .= fread($handle, $size);
> fclose($handle);
> 
> // save both as one audio file
> 
> $filename = "tmp/a.mp3";
> $file = fopen( $filename, "wb" );
> fwrite( $file, $load);
> fclose( $file );
> 
> However, I can't do the same with .WAV files. Does anyone know a way to
> combine .WAV files similar to the way shown above?

If you are using linux I'd just shell out to sox or similar.

BTW the MP3s you produce in the above way are perhaps not that
"prefect". MP3 is a frame based format which means that you can in
theory combine two files quite simply, but I'm not sure how well it will
all work with if the two files are different bit rates or one is a VBR etc.

WAV format is quite similar to raw PCM, but it does have a header. It's
a relatively simple format tho' so the specs are relatively easy to
understand (tho' I've not looked at them for a while.

In theory, it should just be a matter of removing the WAV header from
the second file and concatenating as per your above algorithm, but in
practice it is more complex. WAV allows different sample rates and
channels etc. so you may have to resample the files to allow for simple
concatenation. All in all, I think sox will solve your problems if you
can shell out in linux.

sox is for sound what imagemagick is for graphics.

HTH

Col

--- End Message ---
--- Begin Message ---
At 9:49 PM +0000 2/25/07, Colin Guthrie wrote:
tedd wrote:
 Hi gang:

 I can combine two mp3 sound files together by simply:

 // load  first

 $file = "a.mp3";
 $handle = fopen($file, "rb");
 $size = filesize($file);
 $load = fread($handle, $size);
 fclose($handle);

 // load second

 $file = "b.mp3";
 $handle = fopen($file, "rb");
 $size = filesize($file);
 $load .= fread($handle, $size);
 fclose($handle);

 // save both as one audio file

 $filename = "tmp/a.mp3";
 $file = fopen( $filename, "wb" );
 fwrite( $file, $load);
 fclose( $file );

 > However, I can't do the same with .WAV files. Does anyone know a way to
 > combine .WAV files similar to the way shown above?

If you are using linux I'd just shell out to sox or similar.

I don't know how to do that.

BTW the MP3s you produce in the above way are perhaps not that
"prefect". MP3 is a frame based format which means that you can in
theory combine two files quite simply, but I'm not sure how well it will
all work with if the two files are different bit rates or one is a VBR etc.

WAV format is quite similar to raw PCM, but it does have a header. It's
a relatively simple format tho' so the specs are relatively easy to
understand (tho' I've not looked at them for a while.

In theory, it should just be a matter of removing the WAV header from
the second file and concatenating as per your above algorithm, but in
practice it is more complex. WAV allows different sample rates and
channels etc. so you may have to resample the files to allow for simple
concatenation. All in all, I think sox will solve your problems if you
can shell out in linux.

sox is for sound what imagemagick is for graphics.

I'm aware of what can happen when you combine sound files recorded with different parameters, but that's not a problem here. All files were recorded exactly the same.

I also understand that the problem is probably the headers in the WAV files. However, my dilemma here is how to remove these headers?

For my current problem, it's not necessary that I to do this on the fly -- I don't necessarily need a php solution (unless someone can provide one). I only have 11 very short files (i.e., numbers 0-9, beep, and pause) that need the headers extracted -- and -- I need only one file that contains only a header. From there, I should be able to assemble the sound files that I need.

Any takers -- or suggestions how I can do this on a Mac?

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
>> If you are using linux I'd just shell out to sox or similar.
> 
> I don't know how to do that.

http://uk.php.net/manual/en/ref.exec.php

sox is a command line program that you can experiment with on the
command line.

>From it's man page:

NAME
       SoX - Sound eXchange - The Swiss Army knife of audio manipulation
DESCRIPTION
       SoX  reads  and  writes  audio  files  in  most popular formats
and can
       optionally apply  effects  to  them;  it  can  combine  multiple
 input
       sources,  synthesise audio, and, on many systems, act as a
general pur‐
       pose audio player or a multi-track audio recorder.

       The entire SoX functionality is available using just the ‘sox'
command,
       however,  to simplify playing and recording audio, if SoX is
invoked as
       ‘play', the output file is automatically set to be  the  default
 sound
       device  and if invoked as ‘rec', the default sound device is used
as an
       input source.

       The heart of SoX is a library called ‘Sound Tools'.   Those
interested
       in  extending  SoX  or  using  it in other programs should refer
to the
       Sound Tools manual page: libst(3).

       The overall SoX processing chain can be summarised as follows:

                 Input(s) → Balancing → Combiner → Effects → Output


> Any takers -- or suggestions how I can do this on a Mac?

You should be able to get sox on OSX. I'd imagine it's either easily to
install via a package or it's on fink. Either way you shouldn't have
much trouble.

This way you can just use the shell to do the work. You can do it in PHP
or in any other kind of script.

Hope this helps.

Col

--- End Message ---
--- Begin Message ---
Hi,

I would like to store and retrieve photo from my DB (PostgreSQL).
However, i do not know how to do it.

Where can i find some example ?

thanks a lot,

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.1.4
Apache 2.0.58
PHP 5

--- End Message ---
--- Begin Message ---
Alain Roger wrote:
Hi,

I would like to store and retrieve photo from my DB (PostgreSQL).
However, i do not know how to do it.

Apart from the usual "you shouldn't really store images in the database" comment, the php site has some examples:

To put it in:
http://www.php.net/manual/en/function.pg-escape-bytea.php

To take it back out:
http://www.php.net/manual/en/function.pg-unescape-bytea.php

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
This one time, at band camp, "Alain Roger" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I would like to store and retrieve photo from my DB (PostgreSQL).
> However, i do not know how to do it.

Good idea, dont listen to those who give you the "you should'nt store
images in a database" diatribe.

Here is a little tutorial on the subject, it uses MySQL and PDO but
you simply need to change the connection string to PDO to pgsql.
http://phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html

enjoy
Kevin


-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
Hello again.. I recently posted a question about include files.. I appreciate
the responses I received but my question wasn’t answered.. its my fault I
didn’t explain myself 100%.. I know how to use the include files.. What I am
trying to figure out is. How do I upload the include files into my Include
folder. I cant make the path myself because I don’t have access to the
config file. I have my website on yahoo web hosting. So how do I physically
upload the file into that include folder which is .:/include:/usr/lib/php
residing on my website. I don’t have ftp access to the folder. I cant view
the fold on my ftp program to upload the file.. do I upload it through php
script?  Can I change the path to a folder on my website??  Thank you soo
much everyone!

-- 
View this message in context: 
http://www.nabble.com/Uploading-into-website-directory-for-Php-files-tf3288031.html#a9145868
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
In news: [EMAIL PROTECTED],
StainOnRug  said:
> Hello again.. I recently posted a question about include files.. I
> appreciate
> the responses I received but my question wasn't answered.. its my
> fault I
> didn't explain myself 100%.. I know how to use the include files..
> What I am
> trying to figure out is. How do I upload the include files into my
> Include
> folder. I cant make the path myself because I don't have access to the
> config file. I have my website on yahoo web hosting. So how do I
> physically
> upload the file into that include folder which is
> .:/include:/usr/lib/php
> residing on my website. I don't have ftp access to the folder. I cant
> view
> the fold on my ftp program to upload the file.. do I upload it
> through php
> script?  Can I change the path to a folder on my website??  Thank you
> soo
> much everyone!

If you have no access to the folder you will have to ask your host company 
to do it.
What do you wish to upload?
If you just wish to use something along the lines of:
<?php include_once("../include/footer.php");?>
You can use any folder.

Chris





-- 
Cheap As Chips Broadband http://yeah.kick-butt.co.uk
Superb hosting & domain name deals http://host.kick-butt.co.uk 

--- End Message ---
--- Begin Message ---
On Feb 25, 2007, at 11:30 AM, StainOnRug wrote:


Hello again.. I recently posted a question about include files.. I appreciate the responses I received but my question wasn’t answered.. its my fault I didn’t explain myself 100%.. I know how to use the include files.. What I am trying to figure out is. How do I upload the include files into my Include
folder. I cant make the path myself because I don’t have access to the
config file. I have my website on yahoo web hosting. So how do I physically upload the file into that include folder which is .:/include:/usr/ lib/php residing on my website. I don’t have ftp access to the folder. I cant view the fold on my ftp program to upload the file.. do I upload it through php script? Can I change the path to a folder on my website?? Thank you soo
much everyone!

--
View this message in context: http://www.nabble.com/Uploading-into- website-directory-for-Php-files-tf3288031.html#a9145868
Sent from the PHP - General mailing list archive at Nabble.com.

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


While I will preface this with 'You should ask Yahoo...', I know what a pain it can be to get 'real' answers to your questions from them.

The include directories listed in phpinfo() are for the larger php process (I'm assuming). As far as I know you don't have access to anything but what's in your web root. I'm not sure if they are chrooting something or if it's one of the base_dir things, but your web root is your root so you don't have access to /usr or anything else on the servers file system.

So do like I do and put the include files in an 'includes' directory and through the control panel make that directory private. No one will be able to surf to the directory without a password, but php can reach it fine.
--- End Message ---
--- Begin Message ---
Hi,

i stored all my pictures in my PostgreSQL DB as bytea type.
Now i would like to know how can i display them in my PHP pages ?

where can i find some example ?

thanks a lot,

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.1.4
Apache 2.0.58
PHP 5

--- End Message ---
--- Begin Message ---
Alain Roger escreveu:
Hi,

i stored all my pictures in my PostgreSQL DB as bytea type.
Now i would like to know how can i display them in my PHP pages ?

where can i find some example ?

thanks a lot,

------------------
It is not a good practice to store pictures in DataBases, use links, instead of.
--
zerof
http://www.educar.pro.br/
Apache - PHP - MySQL - Boolean Logics - Project Management
----------------------------------------------------------
Você deve, sempre, consultar uma segunda opinião!
----------------------------------------------------------
Deixe todos saberem se esta informação foi-lhe útil.
----------------------------------------------------------      
You must hear, always, one second opinion! In all cases.
----------------------------------------------------------
Let the people know if this info was useful for you!
----------------------------------------------------------

--- End Message ---
--- Begin Message ---
On 2/25/07, zerof <[EMAIL PROTECTED]> wrote:

Alain Roger escreveu:
> Hi,
>
> i stored all my pictures in my PostgreSQL DB as bytea type.
> Now i would like to know how can i display them in my PHP pages ?
>
> where can i find some example ?
>
> thanks a lot,
>
------------------
It is not a good practice to store pictures in DataBases, use links,
instead of.
--
zerof
http://www.educar.pro.br/
Apache - PHP - MySQL - Boolean Logics - Project Management
----------------------------------------------------------
Você deve, sempre, consultar uma segunda opinião!
----------------------------------------------------------
Deixe todos saberem se esta informação foi-lhe útil.
----------------------------------------------------------
You must hear, always, one second opinion! In all cases.
----------------------------------------------------------
Let the people know if this info was useful for you!
----------------------------------------------------------

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

Indeed. I am building an events directory at the moment that allows
posters to upload images and I store all the images on the file system and
the links in the db.


--
http://www.web-buddha.co.uk

--- End Message ---
--- Begin Message ---
At 7:17 PM +0100 2/25/07, Alain Roger wrote:
Hi,

i stored all my pictures in my PostgreSQL DB as bytea type.
Now i would like to know how can i display them in my PHP pages ?

where can i find some example ?

thanks a lot,

--
Alain


Alain:

I don't know how to extract images from PostgreSQL, but to display image files extracted from MySQL, I use:

$fileType = @mysql_result($result, 0, "image_type");
$fileContent = @mysql_result($result, 0, "image");
header("Content-type: $fileType");
echo ($fileContent);

hth's

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 3:53 PM -0300 2/25/07, zerof wrote:
Alain Roger escreveu:
Hi,

i stored all my pictures in my PostgreSQL DB as bytea type.
Now i would like to know how can i display them in my PHP pages ?

where can i find some example ?

thanks a lot,

------------------
It is not a good practice to store pictures in DataBases, use links, instead of.


<Flame suit on>

Let's not go there again. Both techniques have up-sides and down-sides -- and I use both depending upon needs.

For example, have you ever tried to back-up an image dB? It's a *lot* easier if the files are all stored in a dB rather than in a file system. One is saving just a dB and the other is saving both a dB and the file system (a lot can go wrong there).

Plus, ask that question on a MySQL list and the MySQL experts will not advise you to stay away from storing images in MySQL. And every MySQL book I've ever read that address that issue says that both techniques have valid points.

The *only* ones that I've ever heard complain about storing an image file in a dB have been a few php programmers on this list. And no one, to my knowledge, has ever demonstrated that saving an image in MySQL is poor practice, other than providing lip-service to that effect.

My advice, if it works -- use it. Both techniques are valid, have their advantages, and are good practice.

<Flame suit off>

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---

        Hi,

I am trying to add a search to the site i am developing but i ran into a bit of a problem.

Since the site is mainly dynamic (lots of includes and mysql queries), i thought of building an index table that will contain the insides of all the pages in the site tree. I was thinking of opening each page with fopen, stripping the html, and storing it in a database table. Then i would only search there.

        The problem is that i cant seem to read the pages with fopen:

        example of urls:

        index.php?m=1
        index.php?m=1&s=3

        If i try to do this:

        $page=fopen('index.php?m=1',"r");
        if($page){
                while (!feof($page)) {
                        $buff = fgets($page,4096);
                        $totalpage .= $buff;
                }
        }else{
                echo "error";
        }

I dont get the resolved content in $totalpage, but i get the includes and php commands that are inside index.php, which i find very strange. Should they resolve before they are retrieved?

        Any help is highly appreciated. Thanks.

        Miguel

--- End Message ---
--- Begin Message ---
You can try to do this:

$page=file('index.php?m=1');

By this way your $page will be an array which will have each line of the 
resolved file in each element.


"Miguel Vaz" <[EMAIL PROTECTED]> escreveu na mensagem 
news:[EMAIL PROTECTED]
>
> Hi,
>
> I am trying to add a search to the site i am developing but i ran into a 
> bit of a problem.
>
> Since the site is mainly dynamic (lots of includes and mysql queries), i 
> thought of building an index table that will contain the insides of all 
> the pages in the site tree. I was thinking of opening each page with 
> fopen, stripping the html, and storing it in a database table. Then i 
> would only search there.
>
> The problem is that i cant seem to read the pages with fopen:
>
> example of urls:
>
> index.php?m=1
> index.php?m=1&s=3
>
> If i try to do this:
>
> $page=fopen('index.php?m=1',"r");
> if($page){
> while (!feof($page)) {
> $buff = fgets($page,4096);
> $totalpage .= $buff;
> }
> }else{
> echo "error";
> }
>
> I dont get the resolved content in $totalpage, but i get the includes and 
> php commands that are inside index.php, which i find very strange. Should 
> they resolve before they are retrieved?
>
> Any help is highly appreciated. Thanks.
>
> Miguel 

--- End Message ---
--- Begin Message ---
Miguel Vaz wrote:

    Hi,

I am trying to add a search to the site i am developing but i ran into a bit of a problem.

Since the site is mainly dynamic (lots of includes and mysql queries), i thought of building an index table that will contain the insides of all the pages in the site tree. I was thinking of opening each page with fopen, stripping the html, and storing it in a database table. Then i would only search there.

    The problem is that i cant seem to read the pages with fopen:

    example of urls:

    index.php?m=1
    index.php?m=1&s=3

    If i try to do this:

    $page=fopen('index.php?m=1',"r");

Change that to a url:

$page = fopen('http://www.domain.com/index.php?m=1')

so the webserver has a chance to do it's work.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hi,

I previously sent email about process how to retrieve and save pictures in
postgreSQL DB.

Now i know how to save them in DB, however i would like to know how can i
retrieve the pictures and display them without knowing the picture extension
?
i mean that in my DB i have GIFs, JPGs pictures.

1. My following code display without problem JPEG picture but what about GIF
?
2. How can i display picture without using ==> header('Content-type:
image/jpeg'); Because this must be before displaying pictures.
3. what should i do if i want to display several types of pictures in the
PHP page ?

My code :

<?php

   $dbconn = pg_connect($conn_string)  or die('Could not connect: ' .
pg_last_error());

   $res = pg_query("SELECT * FROM immense.photo where photo_id=20");
   $raw = pg_fetch_result($res, 'photo_image');
   if (!$res)
    {
             echo "An error occured.\n";
             exit;
   }
   else
   {
         header('Content-type: image/jpeg');
         echo pg_unescape_bytea($raw);
   }

   // Closing connection
   pg_close($dbconn);

?>

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.1.4
Apache 2.0.58
PHP 5

--- End Message ---
--- Begin Message ---
At 8:31 PM +0100 2/25/07, Alain Roger wrote:
Hi,

I previously sent email about process how to retrieve and save pictures in
postgreSQL DB.

Now i know how to save them in DB, however i would like to know how can i
retrieve the pictures and display them without knowing the picture extension
?
i mean that in my DB i have GIFs, JPGs pictures.

1. My following code display without problem JPEG picture but what about GIF
?
2. How can i display picture without using ==> header('Content-type:
image/jpeg'); Because this must be before displaying pictures.
3. what should i do if i want to display several types of pictures in the
PHP page ?

My code :

<?php

   $dbconn = pg_connect($conn_string)  or die('Could not connect: ' .
pg_last_error());

   $res = pg_query("SELECT * FROM immense.photo where photo_id=20");
   $raw = pg_fetch_result($res, 'photo_image');
   if (!$res)
    {
             echo "An error occured.\n";
             exit;
   }
   else
   {
         header('Content-type: image/jpeg');
         echo pg_unescape_bytea($raw);
   }

   // Closing connection
   pg_close($dbconn);

?>

That's the type of information you should store in your dB along with the image.

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
> That's the type of information you should store in your dB along with
> the image.

+1

Also you probably want to think about adding some cache related headers
there too in order to stop web browsers hammering your server all the time.

Col

--- End Message ---
--- Begin Message ---
$url =www.mysite.ru/some.txt;

$fa = fopen($url,"r");

/*
$fa = fsockopen("http://mysite.ru";, 80, &$num_error, &$str_error, 30);
if(!$fa)
   { print "Weather is not available: $str_error ($num_error)\n"; }
else
{
  fputs($fa,"GET /some.txt HTTP/1.0\n\n");
  $answer=fgets($fa,128);



I use the above code to read a file on remote server but now I need to read 
it on local server,question is how.

Cheers
Chris

--- End Message ---
--- Begin Message --- Difference: You don't call file as http://www.myweb.com/ but instead you use the path like c:\some.txt or ../some.txt etc.

PHP 5
=====
echo file_get_contents("some.txt");


PHP 4
=====
$fp = fopen("some.txt", "r");
echo  fread($fp, filesize ("some.txt"));
fclose($fp);


Another solution
================
foreach(readfile("some.txt") as $line) echo $line;



-------------------------
Joker7 napsal(a):
$url =www.mysite.ru/some.txt;

$fa = fopen($url,"r");

/*
$fa = fsockopen("http://mysite.ru";, 80, &$num_error, &$str_error, 30);
if(!$fa)
   { print "Weather is not available: $str_error ($num_error)\n"; }
else
{
  fputs($fa,"GET /some.txt HTTP/1.0\n\n");
  $answer=fgets($fa,128);



I use the above code to read a file on remote server but now I need to read it on local server,question is how.

Cheers
Chris


--- End Message ---
--- Begin Message ---
Hi,

Before I start, I am not sure whether I should have sent this to
Memcached or PHP mailing list. So, for those who are subscribed to
both, I apologize.

I have started using the PHP extension at
http://pecl.php.net/package/memcache for memcached. But, one problem I
am having right now is that, php functions tells you nothing about
errors.

For example, when you call Memcache::get, it returns true or false,
but when it returns false does this mean item is not found, or
Memcached is down, or there is a cache corruption / compression error,
etc. etc. And, this also is the case for Memcache::set, again when it
returns false, you have no idea about what is going on. I tried
turning debugging on, and this did not help much.

As far as I can see, memcache internally sets error nos, but this
extension completely ignores this information. And, I saw something like:

"PHP Notice:  Memcache::get(): marked server 'localhost:11211' as
failed" in my php logs for some of the requests (like 5-10 out of a
thousand), but server was up, and everthing was normal, and the
request right after this one succeeded.

In summary, is it possible to get these errors from PHP somehow so
that we can have an idea about what is going on and how we can handle
them? Possibly with something like "mysql_error" or "mysql_errno"
functions?

Thanks in advance...

--- End Message ---

Reply via email to