Re: [PHP] displaying a pdf

2011-06-01 Thread Richard Quadling
On 1 June 2011 06:53, Tamara Temple  wrote:
>
> On May 30, 2011, at 10:01 AM, Jim Giner wrote:
>
>> Thanks for the attempt Simon, but your code only displayed gibberish.
>> While looking around again for help, I found this and it works perfectly:
>>
>> > session_start();
>> //
>> //  Specify the name of the pdf here and the folder
>> //
>> $pdfname='VFD_ByLaws.pdf';
>> $path='/pdfs/';
>> //
>> //  the rest will handle the displaying
>> //
>> header("Cache-Control: no-cache");
>> header("Content-type: application/pdf");
>> header("Location:$path$pdfname");
>> ?>
>
> I may not be fully understanding this, but if you set a Location: header,
> the other headers you've set don't matter at all, since the client will
> merely redirect to the page specified by the Location: header.

Yes. That's true. But the URL you link to is the one responsible for
sending the headers to download a PDF.

Just like if it was a link ...

Got your PDF here

download.pdf.php would send the appropriate headers.



-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



[PHP] Re: smart auto download file

2011-06-01 Thread Jonesy
On Tue, 31 May 2011 21:01:09 +0100, Stuart Dallas wrote:
>
> Sometimes I miss the way the web was before javascript :/

  Sometimes???

Jonesy


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



Re: [PHP] displaying a pdf

2011-06-01 Thread Jim Giner
Well - the code works just fine as is and that's all I care about.  As for 
Richard's comments - the url in my header(Location) statement points to 
a pdf file, not a php file, so the target is not sending any headers (that I 
know of ). 



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



[PHP] building a key value pair dynamically

2011-06-01 Thread Adam Preece
hi all,

is it possible to dynamically build a key value pair array in php from a 
database result?

if so how?

kind regards

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



Re: [PHP] building a key value pair dynamically

2011-06-01 Thread jean-baptiste verrey
with mysql use mysql_fetch_assoc, is that what you are asking for ?

On 1 June 2011 16:31, Adam Preece  wrote:

> hi all,
>
> is it possible to dynamically build a key value pair array in php from a
> database result?
>
> if so how?
>
> kind regards
>
> Adam
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] building a key value pair dynamically

2011-06-01 Thread Adam Preece
sorry i should of explained a little more in depth :-).

i am using smarty templating engine,

and it needs me to pass in an associative array.

only an id column and a the name column.

i know if i use a more specific query, but if i have the result set already 
could i build the array so it suits the template function?

this is the function details:

http://www.smarty.net/docsv2/en/language.function.html.options.tpl

and this is the array im currently fetching.

Array ( [0] => Array ( [id] => 2 [0] => 2 [name] => category 1 [1] => category 
1 [main_nav] => true [2] => true ) [1] => Array ( [id] => 3 [0] => 3 [name] => 
category 2 [1] => category 2 [main_nav] => true [2] => true ) [2] => Array ( 
[id] => 4 [0] => 4 [name] => category 3 [1] => category 3 [main_nav] => true 
[2] => true ) [3] => Array ( [id] => 5 [0] => 5 [name] => category 4 [1] => 
category 4 [main_nav] => true [2] => true ) [4] => Array ( [id] => 6 [0] => 6 
[name] => category 5 [1] => category 5 [main_nav] => true [2] => true ) [5] => 
Array ( [id] => 7 [0] => 7 [name] => category 6 [1] => category 6 [main_nav] => 
false [2] => false ) [6] => Array ( [id] => 8 [0] => 8 [name] => category 7 [1] 
=> category 7 [main_nav] => false [2] => false ) [7] => Array ( [id] => 9 [0] 
=> 9 [name] => category 8 [1] => category 8 [main_nav] => false [2] => false ) 
[8] => Array ( [id] => 10 [0] => 10 [name] => category 9 [1] => category 9 
[main_nav] => false [2] => false ) [9] => Array ( [id] => 11 [0] => 11 [name] 
=> category 10 [1] => category 10 [main_nav] => false [2] => false ) ) Array ( 
[0] => 2=>category 1 [1] => 3=>category 2 [2] => 4=>category 3 [3] => 
5=>category 4 [4] => 6=>category 5 [5] => 7=>category 6 [6] => 8=>category 7 
[7] => 9=>category 8 [8] => 10=>category 9 [9] => 11=>category 10 

hope this makes sense?

kind regards


Adam

On 1 Jun 2011, at 16:33, jean-baptiste verrey wrote:

> with mysql use mysql_fetch_assoc, is that what you are asking for ?
> 
> On 1 June 2011 16:31, Adam Preece  wrote:
> hi all,
> 
> is it possible to dynamically build a key value pair array in php from a 
> database result?
> 
> if so how?
> 
> kind regards
> 
> Adam
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 



Re: [PHP] displaying a pdf

2011-06-01 Thread Tamara Temple


On Jun 1, 2011, at 9:54 AM, Jim Giner wrote:

Well - the code works just fine as is and that's all I care about.   
As for
Richard's comments - the url in my header(Location) statement  
points to
a pdf file, not a php file, so the target is not sending any headers  
(that I

know of ).


The server will send the appropriate headers for files like that. If  
you want to see it, try doing a wget or curl and make sure to snag the  
headers as well (or instead) of the actual file.


For instance:

  curl -O -D headers.txt 
'http://wiki.tamaratemple.com/uploads/Main/CoolWebThings/bumping_locks.pdf'

returns headers.txt:

HTTP/1.1 200 OK
Date: Wed, 01 Jun 2011 18:28:28 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Mon, 03 Dec 2007 02:54:08 GMT
ETag: "9386f8-323dc0-e4df9400"
Accept-Ranges: bytes
Content-Length: 3292608
Content-Type: application/pdf

without doing anything special.

(no, i don't advocate going around picking locks. it's just useful  
info to have...)


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



Re: [PHP] building a key value pair dynamically

2011-06-01 Thread Tamara Temple


On Jun 1, 2011, at 10:40 AM, Adam Preece wrote:


sorry i should of explained a little more in depth :-).

i am using smarty templating engine,

and it needs me to pass in an associative array.

only an id column and a the name column.

i know if i use a more specific query, but if i have the result set  
already could i build the array so it suits the template function?


this is the function details:

http://www.smarty.net/docsv2/en/language.function.html.options.tpl

and this is the array im currently fetching.

Array ( [0] => Array ( [id] => 2 [0] => 2 [name] => category 1 [1]  
=> category 1 [main_nav] => true [2] => true ) [1] => Array ( [id]  
=> 3 [0] => 3 [name] => category 2 [1] => category 2 [main_nav] =>  
true [2] => true ) [2] => Array ( [id] => 4 [0] => 4 [name] =>  
category 3 [1] => category 3 [main_nav] => true [2] => true ) [3] =>  
Array ( [id] => 5 [0] => 5 [name] => category 4 [1] => category 4  
[main_nav] => true [2] => true ) [4] => Array ( [id] => 6 [0] => 6  
[name] => category 5 [1] => category 5 [main_nav] => true [2] =>  
true ) [5] => Array ( [id] => 7 [0] => 7 [name] => category 6 [1] =>  
category 6 [main_nav] => false [2] => false ) [6] => Array ( [id] =>  
8 [0] => 8 [name] => category 7 [1] => category 7 [main_nav] =>  
false [2] => false ) [7] => Array ( [id] => 9 [0] => 9 [name] =>  
category 8 [1] => category 8 [main_nav] => false [2] => false ) [8]  
=> Array ( [id] => 10 [0] => 10 [name] => category 9 [1] => category  
9 [main_nav] => false [2] => false ) [9] => Array ( [id] => 11 [0]  
=> 11 [name] => category 10 [1] => category 10 [main_nav] => false  
[2] => false ) ) Array ( [0] => 2=>category 1 [1] => 3=>category 2  
[2] => 4=>category 3 [3] => 5=>category 4 [4] => 6=>category 5 [5]  
=> 7=>category 6 [6] => 8=>category 7 [7] => 9=>category 8 [8] =>  
10=>category 9 [9] => 11=>category 10


hope this makes sense?


This seems pretty straight-forward.

$options = array();

foreach ($rows as $row) {
$options[]=list($row['id']=>$row['name']);
}

but then maybe i'm not understanding something...


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



Re: [PHP] displaying a pdf

2011-06-01 Thread Ashley Sheridan
On Wed, 2011-06-01 at 13:31 -0500, Tamara Temple wrote:

> On Jun 1, 2011, at 9:54 AM, Jim Giner wrote:
> 
> > Well - the code works just fine as is and that's all I care about.   
> > As for
> > Richard's comments - the url in my header(Location) statement  
> > points to
> > a pdf file, not a php file, so the target is not sending any headers  
> > (that I
> > know of ).
> 
> The server will send the appropriate headers for files like that. If  
> you want to see it, try doing a wget or curl and make sure to snag the  
> headers as well (or instead) of the actual file.
> 
> For instance:
> 
>curl -O -D headers.txt 
> 'http://wiki.tamaratemple.com/uploads/Main/CoolWebThings/bumping_locks.pdf'
> 
> returns headers.txt:
> 
> HTTP/1.1 200 OK
> Date: Wed, 01 Jun 2011 18:28:28 GMT
> Server: Apache/2.2.3 (CentOS)
> Last-Modified: Mon, 03 Dec 2007 02:54:08 GMT
> ETag: "9386f8-323dc0-e4df9400"
> Accept-Ranges: bytes
> Content-Length: 3292608
> Content-Type: application/pdf
> 
> without doing anything special.
> 
> (no, i don't advocate going around picking locks. it's just useful  
> info to have...)
> 


The advantage to having PHP send the correct headers, is that the file
you are linking to does not need to be in a web accessible area, meaning
that it's protected from someone accessing it without passing some form
of security you have in place in your PHP code. Also, it removes any
issues with a server not having been set up correctly, which is quite
often a problem on IIS (Apache is a lot better, but even it has issues
with some less-popular formats)

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Merlin Morgenstern

Hi there,

I am working on a pretty huge site with thousands of files with php 
code. Unfortunatelly the app throws a ton of notices du to missing '' in 
arrays. Of course I could simply disable the output on the dev server to 
surpress notices, but I would rather like to get it fixed.


Has somebody a good idea on how to fix this automated somehow with regex?

The vars are right now: $var[element] and should be $var['element']

I was looking into sed, but I was hoping that there is also a way in 
php. Has anybody a hint on how to get the regex done?


I appreciate any help on that.

Best regards,

Merlin

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



Re: [PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Govinda
> I am working on a pretty huge site with thousands of files with php code. 
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays. Of 
> course I could simply disable the output on the dev server to surpress 
> notices, but I would rather like to get it fixed.
> 
> Has somebody a good idea on how to fix this automated somehow with regex?
> 
> The vars are right now: $var[element] and should be $var['element']
> 
> I was looking into sed, but I was hoping that there is also a way in php. Has 
> anybody a hint on how to get the regex done?
> 
> I appreciate any help on that.


Hi Merlin

I don't know what is sed, (and perhaps this is what you meant by that), but a 
good text editor could do the job in one decent regex, global replace.  Seems 
like asking PHP to do it is the same task, plus the added code (hassle) to walk 
all your directories for affected files.

- Govinda

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



Re: [PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Matt Giddings
You can put an @  symbol in front each item that is throwing the error.
That may take some time though.  You could use something like

find /htdocs_folder -name \*.php -print | xargs sed -i
s/\$array_name/@$array_name/g

That might get you what you're looking for.  But be cautious because this
method does not create a backup file for you.   You can do a quick check
(but not fool proof) by using this command

find /htdocs_folder -name \*.php -print | xargs grep "\$array_name" | more

You may need to remove the slash in front of the $ sign.

Matt

On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Matt Giddings
I was thinking about this a little more and thought that the method I sent
before will work, but it has the potential of clobbering variables that are
not related to this warning/notice.  Best bet would be to create a list of
file names that contain the offending variables then feed that to sed using
cat file_name | sed...  You can use the find | xargs grep method to create
the initial list, then work from there.

On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Adam Richardson
On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I'd use the DirectoryIterator to work through the site and locate all of the
php files:
http://www.php.net/manual/en/directoryiterator.isfile.php

And, once I find
a file, I'd perform a preg_replace such as below:
$php = '$var[element]';

$re_patterns = array(
'/^(\$[a-zA-Z0-9]+\[)([a-zA-Z0-9]+)(\])$/'
);
$re_replaces = array(
'\1"\2"\3'
);
// preg_replace can return null, so must make sure php isn't lost
echo $php = (($temp_php = \preg_replace($pattern = $re_patterns,
$replacement = $re_replaces, $subject = $php)) !== null) ? $temp_php: $php;

I'm confident you can easily use PHP to do this, and hopefully this info is
enough to get you started.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] PHP 5.3.3 operator & problem

2011-06-01 Thread 李白|字一日
hi, all

i currently have a project which using & operator on creating a new object.

like:
  $class =& new Class();

it works properly in  php 5.1.6,
but not in php 5.3.3
and it gives offset errors to me.

is there anyone knows why and how to fix this problem?


Re: [PHP] PHP 5.3.3 operator & problem

2011-06-01 Thread Simon J Welsh
On 2/06/2011, at 2:44 PM, 李白|字一日 wrote:

> hi, all
> 
> i currently have a project which using & operator on creating a new object.
> 
> like:
>  $class =& new Class();
> 
> it works properly in  php 5.1.6,
> but not in php 5.3.3
> and it gives offset errors to me.
> 
> is there anyone knows why and how to fix this problem?

In PHP 5, objects are always assigned by reference, you do not need to make it 
explicit.
---
Simon Welsh
Admin of http://simon.geek.nz/


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



Re: [PHP] PHP 5.3.3 operator & problem

2011-06-01 Thread 李白|字一日
both php 5.1.6 and php 5.3.3 are php 5.
but it seems they are different in processing & operator.

2011/6/2 Simon J Welsh 

> On 2/06/2011, at 2:44 PM, 李白|字一日 wrote:
>
> > hi, all
> >
> > i currently have a project which using & operator on creating a new
> object.
> >
> > like:
> >  $class =& new Class();
> >
> > it works properly in  php 5.1.6,
> > but not in php 5.3.3
> > and it gives offset errors to me.
> >
> > is there anyone knows why and how to fix this problem?
>
> In PHP 5, objects are always assigned by reference, you do not need to make
> it explicit.
> ---
> Simon Welsh
> Admin of http://simon.geek.nz/
>
>


Re: [PHP] notices nightmare - looking for a regex solution

2011-06-01 Thread Hans Åhlin
2011/6/2 Merlin Morgenstern :
> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I don't have the time to write a complete script, but here is an idea
(Pseudocode):

Read dir.
Foreach "File"{

open file
new var $NewFile
new var $Line
  foreach "Line"{
read new line, look for "$?[?]"

   tmp var $Pos = strpos($Line, '[')+1
   tmp var $Pos2 = strpos($NewFile, ']')
   tmp var $Ctrl = true

   while($Ctrl){

if( $Line[$Pos] !='$' && $Line[$Pos] != '\''] && $Line[$Pos] !=
'"']){ //or some reg match (it's probably the wisest to use so you can
find blank spaces before $ ' or "){

add the content of the line before $Pos-1 to $NewFile
add ' or " to $NewFile
add content between $Pos-1 and $Pos2 to $NewFile
add ' or " and the ']' to $NewFile

   search the rest of the line for more arrays in the same way
$Pos = strpos($Line, '[', $Pos2)
$Pos2 = strpos($Line, ']' , $Pos)
if($Pos == false || $Pos2 == false){
$Ctrl = false
}
}else{
   copy the whole line to $NewFile
}
add \r\n to $NewFile
   }
  }
 save file
}
-- 


**
 Hans Åhlin
   Tel: +46761488019
   icq: 275232967
   http://www.kronan-net.com/
   irc://irc.freenode.net:6667 - TheCoin
**

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