php-general Digest 25 Sep 2007 05:06:08 -0000 Issue 5037

Topics (messages 262418 through 262438):

Re: Access name of variable in $_POST array
        262418 by: Eric Lommatsch

Re: Merging PDF Documents
        262419 by: Tom Chubb
        262420 by: Colin Guthrie

Re: Data request
        262421 by: Colin Guthrie

Re: imagecreatefromgif fails for a valid image
        262422 by: Tijnema
        262423 by: Thushara Wijeratna

trouble trying to connect to gmail server.
        262424 by: Fábio Generoso
        262436 by: Chris

article: 7 reasons I switched back to PHP after 2 years on Rails
        262425 by: XIMvad
        262426 by: Robert Cummings
        262431 by: Colin Guthrie

Regex æøå email validation?
        262427 by: Søren Neigaard

Strategy for Secure File Storage
        262428 by: Kevin Murphy
        262429 by: Jon Anderson
        262430 by: Colin Guthrie
        262434 by: Kevin Murphy
        262437 by: brian

Re: Regex æøå email validation?
        262432 by: Per Jessen
        262433 by: mike

Re: Questions about overloading and visibility in PHP5
        262435 by: Larry Garfield

PHP build exits @ "bad magic number (not a Mach-O file)". Ideas?
        262438 by: Aliya Harbouri

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 ---
-----Original Message-----
From: Stut [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 21, 2007 4:12 PM
To: Eric Lommatsch
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Access name of variable in $_POST array

Please include the list when replying.

Eric Lommatsch wrote:
> -----Original Message-----
> From: Stut [mailto:[EMAIL PROTECTED]
> Sent: Friday, September 21, 2007 3:09 PM
> To: Eric Lommatsch
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] Access name of variable in $_POST array
> 
> Eric Lommatsch wrote:
>> I am writing a PHP script that is going to accept variables that are 
>> passed from a PDF form and should write both the name of the variable 
>> and its value to a text file.
>>  
>>  
>> I can get the value that I want to retrieve with out problem. 
>> However, even though I have searched through the PHP.net site and 
>> googled this as well I have not yet been able to find the syntax that 
>> I need to get the names of the variables in the $_Post array.
>>  
>> Can someone point me to the place in the PHP manual where I can find 
>> the syntax to get the name of a variable in the $_POST array?
> 
> http://php.net/array_keys
> 
> As in...
> 
> $varnames = array_keys($_POST);
> 
> -Stut
> 
> --
> http://stut.net/
> 
> Hello Stut,
> 
> That is not exactly what I am looking for. If I try using that in My 
> PHP script what I get as a result of that is repeatedly the Phrase "Post
Array"
> when I check the values there. The PDF form that is posting to the PHP 
> script is passing variable names like "Employer_name" or "Employee_Name". I
am
> hoping to get those variable names.   

Put this line at the top of the script that the form posts to...

print '<pre>'.print_r($_POST, true).'</pre>'; exit;

That will display the contents of the $_POST array and you should be able to
figure out where everything is.

By the sounds of it the posted values are actually in $_POST['Post Array']
but use the above line to be sure.

-Stut

--
http://stut.net/

Sorry, I thought that I had hit reply to all. Apparently I didn't. 

Thanks that appears to actually be what I was looking for.

Thank you
 
Eric H. Lommatsch
Programmer
360 Business 
2087 South Grant Street
Denver, CO 80210
Tel 303-777-8939
Fax 303-778-0378
 
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Unfortunately I can't use shell or install anything on my shared box.
Any other suggestions?

On 24/09/2007, George Pitcher <[EMAIL PROTECTED]> wrote:
> Tom,
>
> I use a Java app called itext to merge PDFs. In my case, it's to add a PDF
> cover created in PHP to a file produced in a wp/ocr package. You need to be
> able to run exec() or shell() to use itext, but its free and quick. Let me
> know if you want more info.
>
> George in Edinburgh
>
> > -----Original Message-----
> > From: Tom Chubb [mailto:[EMAIL PROTECTED]
> > Sent: 24 September 2007 1:24 pm
> > To: PHP General List
> > Subject: [PHP] Merging PDF Documents
> >
> >
> > Please can someone tell me if this is easy to do or whether I should
> > use a package already available...
> >
> > I want to upload a pdf file to a folder then for each subsequent
> > upload, I want it to be appended to the original file. Each pdf is a
> > timesheet, so I want to end up with one file for all timesheets
> > instead of different files every week.
> >
> > What I'd like to know is which function I can use on PHP4?
> > Is it PDF_begin_page_ext?
> > Any help appreciated.
> >
> > Thanks,
> >
> > Tom
> >
> > --
> > Tom Chubb
> > [EMAIL PROTECTED]
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>


-- 
Tom Chubb
[EMAIL PROTECTED]
07912 202846

--- End Message ---
--- Begin Message ---
Tom Chubb wrote:
> Unfortunately I can't use shell or install anything on my shared box.
> Any other suggestions?

I can't remember the syntax but I'm sure there is an easy way to get one
PDF to reference another and distil it into one... I remember this from
way back when (and using Adobe tools which is why the phrase distil was
used...) and it could be completely irrelevant from the context of PHP
functions which I'm not familiar with personally.... so in short, I
can't help :/

Col

--- End Message ---
--- Begin Message ---
Stut wrote:
> Have you tried Google? It knows a lot about most things and a little
> about the rest.

Failing that you could try asking Henry's cat. You must know Henry's
cat? He knows everything about nothing and not to much about that. So if
you know someone who know what he knows then you must know Henry's cat....
</end totally irrelevant 80's cartoon reference>

I'll get my coat....

Col

--- End Message ---
--- Begin Message ---
On 9/24/07, thushw <[EMAIL PROTECTED]> wrote:
>
> I get a failure in creating a gif. php error log shows this:
>
> Sep 24 00:25:47 thushw-laptop apache2: PHP Warning:  imagecreatefromgif() [
> function.imagecreatefromgif function.imagecreatefromgif ]:
> '/home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif'
> is not a valid GIF file in
> /home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/button.php on
> line 30
>
> the gif can be viewed by gthumb. it seems ok.
>
> the problem is only for some gifs. Most gifs, all pngs, jpegs that i've
> tested so far work.
>
> i'm running php5 on ubuntu (uname -a : Linux thushw-laptop 2.6.20.3-ubuntu1
> #2 SMP Sun Apr 15 11:26:58 PDT 2007 i686 GNU/Linux)
>
> phpinfo shows:
>
> gd
> GD Support      enabled
> GD Version      2.0 or higher
> FreeType Support        enabled
> FreeType Linkage        with freetype
> FreeType Version        2.2.1
> T1Lib Support   enabled
> GIF Read Support        enabled
> GIF Create Support      enabled
> JPG Support     enabled
> PNG Support     enabled
> WBMP Support    enabled
>
> from what i've read so far, seems like i need gd lib >=2.0.28. from phpinfo
> output it is not clear if i have the right version. i use: apt-get install
> php5-gd to install gd
>
> these are the files i think are of importance:
>
> /usr/lib/libgd.so.2.0.34
> /usr/lib/libgd.so.2
>
> [the second is a symlink to the first]
>
> >> ls -l /usr/lib/libgd.so.2
> lrwxrwxrwx 1 root root 15 2007-09-24 00:25 /usr/lib/libgd.so.2 ->
> libgd.so.2.0.34
>
> how do i debug this further?  any help greatly appreciated. this problem
> doesn't appear with the gd we have installed on our centos servers. seems to
> happen only on my ubuntu install.
>
> thushara
>

Hello Thushara:

My guess is that your .gif file isn't actually a GIF image (but jpeg, bmp,...).

If you have access to SSH/command line try running
file 
/home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif
and see if it's really a gif, if you don't have access to above, open
the image with any text editor, and see what the first 3 letters say..
If it's an GIF image, it says GIF (GIF89 probably)
if it's an JPEG image, it says something like ÿØÿà
if it's an BMP image, it says BM (BM6)
and if it's an PNG image, it says ‰PNG

I hope this helps you..

Tijnema

--- End Message ---
--- Begin Message ---
Hi Tijnema
It does appear to be a GIF. See output from file command below:
for now, to get by I have copied over a libgd.so verion from a working
centos installation over /usr/lib/libgd.so
thanks,
thushara

>> file 
>> /home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif
/home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif:
GIF image data, version 89a, 1 x 28

On 9/24/07, Tijnema <[EMAIL PROTECTED]> wrote:
> On 9/24/07, thushw <[EMAIL PROTECTED]> wrote:
> >
> > I get a failure in creating a gif. php error log shows this:
> >
> > Sep 24 00:25:47 thushw-laptop apache2: PHP Warning:  imagecreatefromgif() [
> > function.imagecreatefromgif function.imagecreatefromgif ]:
> > '/home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif'
> > is not a valid GIF file in
> > /home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/button.php on
> > line 30
> >
> > the gif can be viewed by gthumb. it seems ok.
> >
> > the problem is only for some gifs. Most gifs, all pngs, jpegs that i've
> > tested so far work.
> >
> > i'm running php5 on ubuntu (uname -a : Linux thushw-laptop 2.6.20.3-ubuntu1
> > #2 SMP Sun Apr 15 11:26:58 PDT 2007 i686 GNU/Linux)
> >
> > phpinfo shows:
> >
> > gd
> > GD Support      enabled
> > GD Version      2.0 or higher
> > FreeType Support        enabled
> > FreeType Linkage        with freetype
> > FreeType Version        2.2.1
> > T1Lib Support   enabled
> > GIF Read Support        enabled
> > GIF Create Support      enabled
> > JPG Support     enabled
> > PNG Support     enabled
> > WBMP Support    enabled
> >
> > from what i've read so far, seems like i need gd lib >=2.0.28. from phpinfo
> > output it is not clear if i have the right version. i use: apt-get install
> > php5-gd to install gd
> >
> > these are the files i think are of importance:
> >
> > /usr/lib/libgd.so.2.0.34
> > /usr/lib/libgd.so.2
> >
> > [the second is a symlink to the first]
> >
> > >> ls -l /usr/lib/libgd.so.2
> > lrwxrwxrwx 1 root root 15 2007-09-24 00:25 /usr/lib/libgd.so.2 ->
> > libgd.so.2.0.34
> >
> > how do i debug this further?  any help greatly appreciated. this problem
> > doesn't appear with the gd we have installed on our centos servers. seems to
> > happen only on my ubuntu install.
> >
> > thushara
> >
>
> Hello Thushara:
>
> My guess is that your .gif file isn't actually a GIF image (but jpeg, 
> bmp,...).
>
> If you have access to SSH/command line try running
> file 
> /home/thushw/mocha_src/LiveMocha/trunk/src/wwwroot/app/webroot/img/new/button-middle.gif
> and see if it's really a gif, if you don't have access to above, open
> the image with any text editor, and see what the first 3 letters say..
> If it's an GIF image, it says GIF (GIF89 probably)
> if it's an JPEG image, it says something like ÿØÿà
> if it's an BMP image, it says BM (BM6)
> and if it's an PNG image, it says ‰PNG
>
> I hope this helps you..
>
> Tijnema
>

--- End Message ---
--- Begin Message ---
Thanks for offer your help.
I will try to explain in details what I did.

First of all, on file php.ini I removed the comments for the line below:

extension=php_imap.dll

After that, I have followed the Gmail instructions to enable POP in my Gmail
account as below:

1. Log in to your Gmail account.
2. Click Settings at the top of any Gmail page.
3. Click Forwarding and POP.
4. Select Enable POP for all mail.
5. Choose "Keep Gmail's copy in the inbox" when messages are accessed with
POP.

When I run the simple code below:

<?
$mbox = 
imap_open('{pop3.gmail.com:995/pop3}INBOX<http://pop3.gmail.com:995/pop3%7DINBOX>',
'<my_login>@ gmail.com', '<my_pass>');
print_r(imap_alerts());
print_r(imap_errors());
$num_mens_not_read = imap_num_recent($mbox);
imap_close($mbox);
?>

I get these errors:

Warning: imap_open(): Couldn't open stream
{pop3.gmail.com:995/pop3}INBOX<http://pop3.gmail.com:995/pop3%7DINBOX>in
c:\arquivos de programas\easyphp1-8\www\index.php on line 2
Array ( [0] => Host not found (#11001): pop3.gmail.com )
Warning: imap_num_recent(): supplied argument is not a valid imap resource
in c:\arquivos de programas\easyphp1-8\www\index.php on line 5
Warning: imap_close(): supplied argument is not a valid imap resource in
c:\arquivos de programas\easyphp1-8\www\index.php on line 6

And, when I run the simple code below:

<?
$mbox = 
imap_open('{pop.gmail.com:995/pop3}INBOX<http://pop.gmail.com:995/pop3%7DINBOX>',
'<my_login>@gmail.com', <my_pass>');
print_r(imap_alerts());
print_r(imap_errors());
$num_mens_not_read = imap_num_recent($mbox);
imap_close($mbox);
?>

I get these errors:

Warning: imap_open(): Couldn't open stream {
pop.gmail.com:995/pop3}INBOX<http://pop.gmail.com:995/pop3%7DINBOX>in
c:\arquivos de programas\easyphp1-8\www\index.php on line 4
Fatal error: Maximum execution time of 30 seconds exceeded in c:\arquivos de
programas\easyphp1-8\www\index.php on line 4
Notice: (null)(): POP3 connection broken in response (errflg=2) in Unknown
on line 0


This second code looks like ok for me, but for some reason I get this time
out. Do you have any idea what's going on? Did I miss some configuration?


Thanks in advance.



On 9/19/07, Chris < [EMAIL PROTECTED]> wrote:
> Fábio Generoso wrote:
> > I have a little trouble while trying to connect to gmail server.
> > I already enabled POP on gmail.
> > After experience a lots of errors with the command below, now I'm
> > seeing no more errors, but it still doesn't working, the page stay
> > processing and just is broke after this command.
> >
> > $mbox = imap_open('{ 
> > pop.gmail.com:995/pop3}INBOX<http://pop.gmail.com:995/pop3%7DINBOX>
',
> > '[EMAIL PROTECTED]', 'my_pass');
>
> What is $mbox at this point? A resource or false?
>
> print_r(imap_alerts());
> print_r(imap_errors());
>
> anything in those?
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>

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

Array ( [0] => Host not found (#11001): pop3.gmail.com )

So pop3.gmail.com doesn't exist.

<?
$mbox = 
imap_open('{pop.gmail.com:995/pop3}INBOX<http://pop.gmail.com:995/pop3%7DINBOX>',
'<my_login>@gmail.com', <my_pass>');
print_r(imap_alerts());
print_r(imap_errors());
$num_mens_not_read = imap_num_recent($mbox);
imap_close($mbox);
?>

I get these errors:

Warning: imap_open(): Couldn't open stream {
pop.gmail.com:995/pop3}INBOX<http://pop.gmail.com:995/pop3%7DINBOX>in
c:\arquivos de programas\easyphp1-8\www\index.php on line 4
Fatal error: Maximum execution time of 30 seconds exceeded in c:\arquivos de
programas\easyphp1-8\www\index.php on line 4
Notice: (null)(): POP3 connection broken in response (errflg=2) in Unknown
on line 0


This second code looks like ok for me, but for some reason I get this time
out. Do you have any idea what's going on? Did I miss some configuration?

Line 4 is

$num_mens_not_read = imap_num_recent($mbox);

so it's taking too long to work out how many are recent.

How many unread messages are there in your account? How many messages in total?

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

--- End Message ---
--- Begin Message ---
hohoho .. maaanya :D
http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html
--

Cordialmente

Victor Anaya / Analista Programador

*****************************************
Apisdev S.A.C. - Integral Solutions
http://www.apisdev.com
[EMAIL PROTECTED]
Tel: (511) 271-7154
Av. Caminos del Inca 1064 Of 4 - Surco

*****************************************
Aviso de Confidencialidad
El presente correo electrónico y/o material adjunto es para uso exclusivo de la persona o entidad a la que expresamente se le ha enviado, puede contener información confidencial o material privilegiado. Si usted no es el destinatario legítimo del mismo, por favor repórtelo inmediatamente al remitente del correo y bórrelo. Cualquier revisión, retransmisión, difusión o cualquier otro uso de este correo, por personas o entidades distintas a las del destinatario legítimo, queda expresamente prohibido.
--- End Message ---
--- Begin Message ---
On Mon, 2007-09-24 at 12:52 -0500, XIMvad wrote:
> hohoho .. maaanya :D
> http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html


DUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUPE!!!

Posted yesterday! :)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
> On Mon, 2007-09-24 at 12:52 -0500, XIMvad wrote:
>> hohoho .. maaanya :D
>> http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html
> 
> 
> DUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUPE!!!
> 
> Posted yesterday! :)

This is why everyone accuses us PHPites of rewriting everything :p

Col

--- End Message ---
--- Begin Message ---
Hi guys

Im helping a friend with hes internet site, and I have found this regex email validation regex on the internet:

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a- z]{2,6}(?:\.[a-z]{2})?)$/i;
if(!filter.test(email)) {
        return false;
}

It works fine, but my friend strangely enough has users with special danish letters (æøåÆØÅ) in their email address, and that it does not accept. Regex is black magic to me, I have tried to modify it in different ways, but with no luck.

I know its not PHP specific (its JavaScript), but maybe one of you can help me anyways?

Best regards
Søren

Attachment: smime.p7s
Description: S/MIME cryptographic signature


--- End Message ---
--- Begin Message --- I'm working on a intranet site that uses an LDAP server to authenticate users and then a integrated CMS (kind of like a wiki with security features so only certain people can post things or upload files) runs the whole thing. (The CMS is custom built with PHP).

I've got a need to make certain files secured so that if someone uploads a file they can specify that no one except certain people can view the file. I've got all the security features set up, what I need to do is come up with the best way of securing those files. Obviously the link won't show to those files if the user doesn't have access to it, but I'm worried that someone might know the link and be able to access the file that they are not supposed be able to see.

This doesn't need to be NSA level security, but I do need to protect against some computer savvy users. So, I'm pondering the following ideas for hiding those files. Any insight on the best method would be appreciated:

1) Write secure files to MySQL as a blob (only secure files would be written there)

2) Write secure files to the level below the web root and come up with a way of copying the files over to a temporary directory for access, then delete the files as soon as they are accessed.

3) Use Unix passwords to protect a folder in the web level and then the CMS knows the password and can pass the password for access (so that the user doesn't know this password, but the CMS does).

4) Some various forms of link obfuscation, where the CMS goes through all the secure files once an hour or so and rewrites the file name with a random string.

5) Or ???? I'm open to suggestions.
Thanks.

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
--- End Message ---
--- Begin Message ---
Kevin Murphy wrote:
I'm working on a intranet site that uses an LDAP server to authenticate users and then a integrated CMS (kind of like a wiki with security features so only certain people can post things or upload files) runs the whole thing. (The CMS is custom built with PHP).

I've got a need to make certain files secured so that if someone uploads a file they can specify that no one except certain people can view the file. I've got all the security features set up, what I need to do is come up with the best way of securing those files. Obviously the link won't show to those files if the user doesn't have access to it, but I'm worried that someone might know the link and be able to access the file that they are not supposed be able to see.

This doesn't need to be NSA level security, but I do need to protect against some computer savvy users. So, I'm pondering the following ideas for hiding those files. Any insight on the best method would be appreciated:

1) Write secure files to MySQL as a blob (only secure files would be written there)

2) Write secure files to the level below the web root and come up with a way of copying the files over to a temporary directory for access, then delete the files as soon as they are accessed.

3) Use Unix passwords to protect a folder in the web level and then the CMS knows the password and can pass the password for access (so that the user doesn't know this password, but the CMS does).

4) Some various forms of link obfuscation, where the CMS goes through all the secure files once an hour or so and rewrites the file name with a random string.

5) Or ???? I'm open to suggestions.


You can easily force all file access to pass through a PHP script -> just do this kind of thing:

- Fetch file information from a get variable, like file.php?fileid=12345 (or even file.php?filename=somefile.bin) - Check if the user is allowed access to that file (yes: continue, no: display an error)

header("Content-Type: " . $file->getContentType());
readfile("/path/to/secure/" . $file->getFileName());

Then just make sure that the "/path/to/secure/" (as in the example above) is not readable by web users by some means.

jon

--- End Message ---
--- Begin Message ---
Kevin Murphy wrote:
> 1) Write secure files to MySQL as a blob (only secure files would be
> written there)

Personally I don't like this strategy but it is always a hot topic on
this list. I don't mind storing a few small images in the db but when
you start to store >200-300Megs it just complicates your database backup
strategy. If you use snapshot-based filesystem level backups (e.g. using
LVM) then this is mitigated but still has many downsides IMO.

> 3) Use Unix passwords to protect a folder in the web level and then the
> CMS knows the password and can pass the password for access (so that the
> user doesn't know this password, but the CMS does).

Nah... seems to complex.

> 4) Some various forms of link obfuscation, where the CMS goes through
> all the secure files once an hour or so and rewrites the file name with
> a random string.

Still not 100% secure and overly complex IMO.

> 2) Write secure files to the level below the web root and come up with a
> way of copying the files over to a temporary directory for access, then
> delete the files as soon as they are accessed.

> 5) Or ???? I'm open to suggestions.

I think you are kind of on the right track with 2 but there is no need
to do this copying.

Simply put all requests for your file through a PHP script. This can be
done with PATH_INFO or mod-rewrite in Apache (just google this for examples.

You PHP script will then check the access credentials of the user (e.g.
a logged in Session) and then output relevent cache headers (again
google) before issuing a Content-Type header with the correct mime type
for the file in question along with the Content-Length header with the
physical size of the file (not strictly speaking necessary but nicer for
the client) before simply calling
"include('/path/to/file/not/in/webroot.ext') to push the content to the
user.

Hope this helps.

Col

--- End Message ---
--- Begin Message --- Ok, I'm almost there. I took what everyone said (and a few Google searches later) and built this, which works great on Firefox and Safari (both mac and PC). The $path leads to a directory outside the web root, and there is also an array with all the mime types in it ($mimetype).


$file_path = $path."/".$file;

$ext = explode(".",$file);

$filesize = filesize($file_path);

$extension = $mimetypes["$ext[1]"];

header("Content-type: $extension");
header("Content-length: $filesize");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Pragma: no-cache");
$file = file_get_contents($file_path);
echo ($file);

The problem is IE7. All browsers work with this code as is but IE says "Internet Explorer cannot download test.pdf from XXX...."

Any suggestions?

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
--- End Message ---
--- Begin Message ---
Kevin Murphy wrote:
Ok, I'm almost there. I took what everyone said (and a few Google searches later) and built this, which works great on Firefox and Safari (both mac and PC). The $path leads to a directory outside the web root, and there is also an array with all the mime types in it ($mimetype).


$file_path = $path."/".$file;

$ext = explode(".",$file);

$filesize = filesize($file_path);

$extension = $mimetypes["$ext[1]"];

header("Content-type: $extension");
header("Content-length: $filesize");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Pragma: no-cache");
$file = file_get_contents($file_path);
echo ($file);

The problem is IE7. All browsers work with this code as is but IE says "Internet Explorer cannot download test.pdf from XXX...."

Any suggestions?


echo 'Your software provider sucks eggs. Get a better browser.';

heh ...

I just did precisely this (the script, not the "sucks eggs" comment) for a project i'm working on. There's a file store above document root and a script that does user validation, then reads the top dir of the file store and display links for each directory or file in there (of course, they're not direct links), letting the user drill down as far as it goes.


What exactly is in the var $extension?
header("Content-type: $extension");


Don't do this:
$file = file_get_contents($file_path);
echo ($file);

Do this instead:
readfile($file_path);
exit;


Here's the business end of my script:

-- snip --
header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header ('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-length: ' . filesize($filepath));
header('Content-disposition: attachment; filename="' . basename($filepath) .'"');
readfile($filepath);
exit;
-- snip --

Note that i'm not trying to give the option for the browser to hand off the file to a "helper application" or plugin. This script is for downloading only, hence no MIME type and the "octet-stream' & 'attachment'.

I just checked another project where i did pass the MIMIE to allow for the file to open in Adobe Reader, MSExcel, etc. You also might want to add these two with your no-cache header:

header ('Expires: Mon, 1 Apr 1974 05:00:00 GMT');
header ('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT');

I seem to remember that it was IE that wanted these in order to play nice.

brian

--- End Message ---
--- Begin Message ---
Søren Neigaard wrote:

> Hi guys
> 
> Im helping a friend with hes internet site, and I have found this
> regex email validation regex on the internet:
> 
> var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-
> z]{2,6}(?:\.[a-z]{2})?)$/i;
> if(!filter.test(email)) {
> return false;
> }
> 
> It works fine, but my friend strangely enough has users with special
> danish letters (æøåÆØÅ) in their email address, and that it does not
> accept. Regex is black magic to me, I have tried to modify it in
> different ways, but with no luck.
> 
> I know its not PHP specific (its JavaScript), but maybe one of you
> can help me anyways?

Hej Søren

to get it to work, you need to be in the Danish locale, otherwise "æøå"
won't be recognised as being word-characters. In javascript, I'm not
sure, but maybe you have to use UTF-8?


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
On 9/24/07, Per Jessen <[EMAIL PROTECTED]> wrote:
> > Hi guys
> >
> > Im helping a friend with hes internet site, and I have found this
> > regex email validation regex on the internet:
> >
> > var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-
> > z]{2,6}(?:\.[a-z]{2})?)$/i;
> > if(!filter.test(email)) {
> > return false;
> > }
> >
> > It works fine, but my friend strangely enough has users with special
> > danish letters (æøåÆØÅ) in their email address, and that it does not
> > accept. Regex is black magic to me, I have tried to modify it in
> > different ways, but with no luck.
> >
> > I know its not PHP specific (its JavaScript), but maybe one of you
> > can help me anyways?

have you looked into http://php.net/filter functions?

not sure if those are locale-friendly or not. if(filter_var($foo,
FILTER_VALIDATE_EMAIL)) {} has worked for me. i don't use any extended
characters though. but changing your locale in PHP might allow it to
work.

--- End Message ---
--- Begin Message ---
On Tuesday 18 September 2007, Andrew Ballard wrote:

> > I'm guessing that the answer to all of my questions is some how
> > wrapped up in visibility and overloading.  Unfortunately I cannot find
> > any resource that documents the interactions.  TIA.
>
> As I understand it, the __get and __set do not ignore visibility;
> rather, they only work for accessing private members. If a property is
> declared public, it does not need the __get and __set, so they aren't
> used. Likewise, $bar->y is public since it was added dynamically
> outside the class.
>
> Andrew

Untrue.  If a property exists, then it is used as-is and 
__get()/__set()/__isset()/__unset() are never called.  The property behaves 
normally, as if those methods were not defined.  If they're not defined, the 
magic methods do whatever they do, which can include adding more properties 
to the object if appropriate (thus bypassing the magic methods in the 
future).

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message ---
Hi everybody!

I'm working on building a few "similar" Dev machines on different OSs.

I've finished a source build of PHP_5_2 branch cvs on a FreeBSD box.
Went smoothly!

I've tried the same on an OSX box.  It's got mostly the same
built-from-source prereqs in place as the FreeBSD box.

But, building PHP_5_2 on OSX keels over at,

        ...
        gcc -bundle -bundle_loader /usr/local/apache2/sbin/httpd
-L/usr/local/bdb46/lib -L/usr/local/sqlite/lib -L/usr/local/lib
-L/usr/local/apache2/lib -laprutil -ldb-4.6 -lsqlite3
/usr/local/mysql/lib/mysql/libmysqlclient_r.la -lexpat -liconv
-L/usr/local/apache2/lib -lapr -lpthread -g -O2 -DZTS
-L/usr/local/lib -L/usr/local/ssl/lib -L/usr/local/bdb46/lib
ext/libxml/libxml.o ext/openssl/openssl.o ext/openssl/xp_ssl.o
ext/pcre/php_pcre.o ext/zlib/zlib.o ext/zlib/zlib_fopen_wrapper.o
ext/zlib/zlib_filter.o ext/date/php_date.o
        ...
        Zend/zend_exceptions.o Zend/zend_strtod.o Zend/zend_objects.o
Zend/zend_object_handlers.o Zend/zend_objects_API.o
Zend/zend_default_classes.o Zend/zend_execute.o
sapi/apache2handler/mod_php5.o sapi/apache2handler/sapi_apache2.o
sapi/apache2handler/apache_config.o
sapi/apache2handler/php_functions.o main/internal_functions.o
-ldb-4.5 -lz -lpcre -lssl -lcrypto -lm -lxml2 -lz -liconv -lm
-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lxml2 -lz -liconv -lm  -o
libs/libphp5.bundle && cp libs/libphp5.bundle libs/libphp5.so
        /usr/bin/ld: /usr/local/mysql/lib/mysql/libmysqlclient_r.la bad magic
number (not a Mach-O file)
        collect2: ld returned 1 exit status
        make: *** [libs/libphp5.bundle] Error 1


I don't know exactly why MySql libs are involved here.  I'm NOT
configuring the build for any MySQL-related modules to be built; I'll
do those separately as extensions, later.  During ./configure output,
I make sure I see

        ...
        checking for MSSQL support via FreeTDS... no
        checking for MySQL support... no
        ...
        checking for MySQLi support... no
        checking whether to enable embedded MySQLi support... no
        ...
        checking for MySQL support for PDO... no
        ...

The only source I've been able to find for the -lmysqlclient_r references is,

        apu-1-config --libs
         -ldb-4.6   -lsqlite3  /usr/local/mysql/lib/mysql/libmysqlclient_r.la
 -lexpat -liconv

Which probably gets picked up from PHP's ./configure,

        ./configure --with-apxs2=/usr/local/apache2/sbin/apxs ...

I'm guessing here, but I figure this 'bad magic number' biz is an
OSX-only thing.  About which I don't know a bunch :-(

Any suggestions as to what to do here?

Thanks a lot! :-)

Ali

--- End Message ---

Reply via email to