php-general Digest 14 Mar 2010 23:56:56 -0000 Issue 6639

Topics (messages 302796 through 302816):

Re: I need a fresh look at storing variables in MySQL
        302796 by: Ashley Sheridan
        302797 by: Rene Veerman
        302798 by: Rene Veerman
        302799 by: Ashley Sheridan
        302816 by: Jochem Maas

SimpleXML: convert xml to text
        302800 by: Dasn
        302801 by: Ashley Sheridan
        302815 by: Dasn

gmail filter test
        302802 by: bruce
        302803 by: Ashley Sheridan

php - page flow issue...
        302804 by: bruce
        302809 by: Rene Veerman

php-cli
        302805 by: Rick Pasotto
        302806 by: Ashley Sheridan
        302811 by: Rick Pasotto
        302814 by: Ashley Sheridan

Re: CodeBubbles -- the coolest IDE innovation since since syntax highlighting 
and intellisense
        302807 by: Nathan Rixham

Using FreeType2 without having to suffer GD
        302808 by: PmI

Change displayed file name to download
        302810 by: Php Developer
        302812 by: Kim Madsen
        302813 by: Peter Lind

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2010-03-14 at 12:14 +0100, Rene Veerman wrote:

> 
> 
> 
> On Sun, Mar 14, 2010 at 11:16 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> 
>         
>         
>         
>         That function won't always work. You're using a PHP version
>         check for mysql_real_escape_string() when the most likely
>         failure point for it is if no database connection has been
>         opened.
>         
> 
> I never call it without an open db connection..
>  
>         
>         Also, you shouldn't strip the tags from a string that's being
>         inserted into the database. strip_tags() is for the display of
>         data on a web page. It's best practice not to alter the actual
>         data you've stored but to convert it once it's displayed.
>         Don't forget that the browser display may not be the only use
>         for that data.
>         
> 
> 
> Let's call that a coder's / payer's preference..
> 
> If i'd need human text, i'd want to strip it of computer code before
> it enters the db. Possibly log the attempt to insert code.
> 
>  
> 
> 


I have to deal with a lot of CMS's, so I expect the users to enter some
HTML code through a rich-text editor, and they expect to be able to.

Aside from that, it's good to have a complete copy of the code a user
attempted to insert, to see the methodology of an attack should it ever
occur.

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



--- End Message ---
--- Begin Message ---
On Sun, Mar 14, 2010 at 12:13 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

>
> I have to deal with a lot of CMS's, so I expect the users to enter some
> HTML code through a rich-text editor, and they expect to be able to.
>

I'd love to have a copy of whatever function you use to filter out bad
HTML/js/flash for use cases where users are allowed to enter html.
I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
for it.


>
> Aside from that, it's good to have a complete copy of the code a user
> attempted to insert, to see the methodology of an attack should it ever
> occur.
>

I should've said "possibly log & mail the details of the attempt", which is
what i'd do ;)

--- End Message ---
--- Begin Message ---
On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman <rene7...@gmail.com> wrote:
>
> I'd love to have a copy of whatever function you use to filter out bad
> HTML/js/flash for use cases where users are allowed to enter html.
> I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
> for it.
>

oh, and even <img> tags can be used for cookie-stuffing on many browsers..

--- End Message ---
--- Begin Message ---
On Sun, 2010-03-14 at 12:25 +0100, Rene Veerman wrote:

> On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman <rene7...@gmail.com> wrote:
> >
> > I'd love to have a copy of whatever function you use to filter out bad
> > HTML/js/flash for use cases where users are allowed to enter html.
> > I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
> > for it.
> >
> 
> oh, and even <img> tags can be used for cookie-stuffing on many browsers..
> 


Yes, and you call strip_tags() before the data goes to the browser for
display, not before it gets inserted into the database. Essentially, you
need to keep as much original information as possible.

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



--- End Message ---
--- Begin Message ---
Op 3/14/10 11:45 AM, Ashley Sheridan schreef:
> On Sun, 2010-03-14 at 12:25 +0100, Rene Veerman wrote:
> 
>> On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman <rene7...@gmail.com> wrote:
>>>
>>> I'd love to have a copy of whatever function you use to filter out bad
>>> HTML/js/flash for use cases where users are allowed to enter html.
>>> I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
>>> for it.
>>>
>>
>> oh, and even <img> tags can be used for cookie-stuffing on many browsers..
>>
> 
> 
> Yes, and you call strip_tags() before the data goes to the browser for
> display, not before it gets inserted into the database. Essentially, you
> need to keep as much original information as possible.

I disagree with both you. I'm like that :)

let's assume we're not talking about data that is allowed to contain HTML,
in such cases I would do a strip_tags() on the incoming data then compare
the output ofstrip_tags() to the original input ... if they don't match then
I would log the problem and refuse to input the data at all.

using strip_tags() on a piece of data everytime you output it if you know
that it shouldn't contain any in the first is a waste of resources ... this
does assume that you can trust the data source ... which in the case of a 
database
that you control should be the case.

at any rate, strip_tags() doesn't belong in an 'anti-sql-injection' routine as
it has nothing to do with sql injection at all.

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


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

Hello, I want to convert some xml stuff to simple string using php, say:

<?php

$string = <<<XML
<a> left <foo>center1<ok>ok</ok>center2</foo>right </a>
XML;

$xml = simplexml_load_string($string);
echo $xml;
?>
The code will output "left right" while all the central stuff was lost.
How should I print it as "left center1 ok center2 right" ?

Thanks in advance, and please Cc me. :)

--
Dasn


--- End Message ---
--- Begin Message ---
On Sun, 2010-03-14 at 21:58 +0800, Dasn wrote:

> Hello, I want to convert some xml stuff to simple string using php, say:
> 
> <?php
> 
> $string = <<<XML
> <a> left <foo>center1<ok>ok</ok>center2</foo>right </a>
> XML;
> 
> $xml = simplexml_load_string($string);
> echo $xml;
> ?>
> The code will output "left right" while all the central stuff was lost.
> How should I print it as "left center1 ok center2 right" ?
> 
> Thanks in advance, and please Cc me. :)
> 
> -- 
> Dasn
> 
> 


Can't you just call strip_tags() on the string? As you don't need to
echo any attribute values, I would have thought it would be perfect. As
XML is meant to be well-formed anyway, strip_tags shouldn't cause any
problems with broken or missing closing tags.

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



--- End Message ---
--- Begin Message ---
On Sun, 14 Mar 2010 22:02:22 +0800, Ashley Sheridan wrote:

On Sun, 2010-03-14 at 21:58 +0800, Dasn wrote:

Hello, I want to convert some xml stuff to simple string using php, say:

<?php

$string = <<<XML
<a> left <foo>center1<ok>ok</ok>center2</foo>right </a>
XML;

$xml = simplexml_load_string($string);
echo $xml;
?>
The code will output "left right" while all the central stuff was lost.
How should I print it as "left center1 ok center2 right" ?

Thanks in advance, and please Cc me. :)



Can't you just call strip_tags() on the string? As you don't need to
echo any attribute values, I would have thought it would be perfect. As
XML is meant to be well-formed anyway, strip_tags shouldn't cause any
problems with broken or missing closing tags.

Thanks Ashley for your reply.
Sorry that my description was not clear enough.
Actually I don't want to just strip the tags, sometimes I also wanna change some elements. For another example: "<a>bla<function>strip_tags</function>bla</a>". When output, I also want to make some change to the data depending on the tags, say, trying to append a pair of "()" to the "<function>" element, printing it as "bla strip_tags() bla". The problem is when I processing the nodes with SimpleXML, I couldn't get the right order of the data. That is : "echo $xml->a, (string) $xml->a->function . '()'" // prints "bla bla strip_tags()"

Thank you anyway. Cc please.

--
Dasn


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

--- End Message ---
--- Begin Message ---
On Sun, 2010-03-14 at 08:37 -0700, bruce wrote:

> test
> 


test received!

what were we test bunnies for again? :p

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



--- End Message ---
--- Begin Message ---
hi.

got a situation for a potential page that i'm playing with. i'm trying
to figure out how to implement it, and the best/good approach to this.
i'm actually considering integrating this kind of process within a cms
(joomla/mambo/cmsms/etc..) but right now, this is in the initia
thought stage...

if you have a thought/page that i can lok at that's actually
implementing this kind of flow.. i'd really like to see it..

so, here goes...

===============================================

--need to figure out a way to have the user invoke an action on the
top section of
 a page, and have that action, trigger an action on a separate part of the page


example:

i have a page that looks something like this:

 +---------------------------------------------------------------+

     initial navbar stuff (always shown on the page)

     <form name="foo">
       stateList (select/option)
     </form>


     +----------------------------------+
       <form name="cat"> based on the user
         selected state                             {
          <tbl name="dog"> based on the user        {  <<<<< based on
the selected state
           user state                               {
                                                    {
          "cancelBTN"  "submitBTN"
       </form>

     +----------------------------------+

                                                        (page1)
 +---------------------------------------------------------------+

i need to have a way to have the user select a "state" from the
 statelist, and to then have the tbl/section of the site under
 the "cat" form, generated, based on the selected state.

at the same time, i need a way to have the user select an item
 from the "dog" tbl, and to have the user select the
 cancelBTN/submitBTN, with the app then generating the
 subsequent action/logic. the page below, is a kind of
 example of what i'm thinking of...

 +---------------------------------------------------------------+

     initial navbar stuff (always shown on the page)

     <form name="foo">
       stateList (select/option)
     </form>


     +----------------------------------+
       <form name="cat2"> based on the user
         selected state, and the cat1.submitBTN

          confirmation section
                                                              {
           based on the user selection from page1/cat1        { <<<
based on the previous
           cancel/submitBTN                                   {
cancel/submitBTN

          "cancelBTN"  "submitBTN"
       </form>

     +----------------------------------+

                                                        (page2)
 +---------------------------------------------------------------+


i can see a couple of ways of accomplishing this...

1) i can have a page of logic, that is composed of a bunch of
 logic, that is basically an "if block", that generates/displays
 the different parts of the page, based on the user actions of
 the preceding pages/sections (the cancel/submitBTNs). this approach
 would essentially require the entire page to be regenerated with
 each BTN selection.

 the logic would generate/invoke the correct page elements based
 on the user selection/action of the previous page/section.

2) i could possibly utilize div/frames, to allow the content in
 the targeted div/frame to be updated/redrawn/regenerated based
 on the user action/selection of the previous page/section...

 this might be able to be done (not familiar with the
 underlying processes to know if this is doable/suitable)
 or even a goof approach..

 would this apaproach still require the entire page to be
 redrawn? or just the portion that's in the targeted
 div/frame...

3) somehow invoke javascript/ajax function/features/logic,
 to allow the actions/interaction to occur, such that the
 content in the targeted div/frame is modified, without
 requiring the rest of the page to be modified...

 i have no idea if this is doable, or what this would mean,
 or involve, or how to apprach this..


or, there might be a different way of accomplishing this
 that i haven't even thought of...

any example sites/docs/code would be greatly appreciated...
heck, i'd even be glad to see an actual site/code that
demonstrates how this can/might/should be implemented!!!


thoughts/comments...

thanks

--- End Message ---
--- Begin Message ---
sounds like you want to build an ajax site with global config settings
per subpart(=functionality) for each browser-client.

if it got it right your other requirements are;
- you have run-time config/state settings per subpart instance that
other subparts' instances need to access.
- you want to be able to load subparts within subparts on the site,
also with varying configs.

so i'd say you need a $_SESSION['config'] = array (array(....)).

if you need to store your config, put it in a mysql db with
adodb.sf.net, single table, fields: userID (varchar(250)),
sessionStartDate (datetime), [more fields], config (text).
$sql = 'insert into config (userID,config) values
("'.antiSQLinjection($userID).'",
"'.antiSQLinjection(json_encode($SESSION['config'])).'");';
$q=$adoDBconn->execute($sql); if ($q!==false) { echo 'config updated.'
};

don't bother to make a sql datamodel for the config until it's old and
rusted, or you'll waste much time updating it when your app evolves.

anyways, all subparts need a unique name.
and all instances of any subpart also need an (autogenerated via
random-string / start-date-time) ID/name.
an instance is a running copy of a subpart, with it's own $localConfig.

and all variables in a config for a subpart need to get short yet
descriptive, standarized names. without a prefix.
this is to allow "superglobals" to be overriden by "more local config settings".

$_SESSION['config'] = array (
  'subparts' => array (
     'subPart1Name' => array (
        'global' => array ( /* all browser-specific variables for
subPart1Name, "global" level */ ),
  )),
  'instances' => array (
    'subPart1Name_instance1-ID' => array ( /* all overridden settings
for subPart1Name used in subPart1InstanceID */)
  ),
  'currentSiteLayout' => array(
    'topLevel' => array (
      'subPart1Name_instance1-ID' => array(),
      'subPart5Name_instance2-ID' => array(
         'children' => array (
            'subPart8Name_instance1-ID' => array()
         )
      )
     )
   )
);
Because this allows for much flexibility, that also means it can get messy.
Be careful not to put paradoxes in such a config array.
Or sensitive data.

But it does allow for saving all runtime config settings for any
number of apps on a web desktop, with any number of child-apps per
app.

You need a way to load these subparts without loading too much code.
Let's put the "front-end for a subpart" in a script filename &
function-name that can be called polymorphically.
$subpartIncludeFile = HD_ROOT.'php/subpart_'.$subPartName.'.php';
And lets give each such script at least a function named
'loadHTML_subpart_'.$subPartName ($configArray);
This function should return the HTML needed for the subpart given a
possible $configArray, and this function should call CMS-level
functions to query &/ update the $_SESSION['config'] aswell.

And let's make a single script to load a div with a subpart, to be
called from javascript;
/php/loadSubpart.php?name=subPartName&config={array_as_json_urlencoded}
obviously this will include only the relevant $subpartIncludeFile =
HD_ROOT.'php/subpart_'.$subPartName.'.php';

Centralize your CMS/MVC logic in a single (or a few) require_once()
script(s) and require_once() them at the top of index.php (and at the
top of /php/subpart_xyz.php);
/php/myCMSfunctions.php

Your index.php can put out HTML that uses ajax at all times to load
subparts, or it can push all required html for a page out in 1 go.
Afterall, it has access to the (stored) $_SESSION['config'], and can
load and run the subparts like the ajax script /php/loadSubpart.php
would.
The latter is better imo because it saves some overhead.

As for the javascript end, i recommend jquery.com to simplify all ajax handling.
Their docs are quite good too.
You'll at least need to build a javascript function
loadSubpart(divID_string, subpartName_string, configOverride_array).

Best to put all your CMS' js functions in a single js object from the
start, to keep the namespace clean.
For an example of how to set something like that up, have a look at
http://mediabeez.ws/htmlMicroscope-1.3.0/hm.source.js (site may be
offline for hours sometimes, check "htmlmicroscope" via google and use
the googlecode link to get a copy)

If you need the entire config on the js end (security risks!) then use
json_encode to transfer between php and js. JS has no native
json_encode, but there are several good ones for free on json.org

good luck :)

On Sun, Mar 14, 2010 at 5:53 PM, bruce <badoug...@gmail.com> wrote:
> hi.
>
> got a situation for a potential page that i'm playing with. i'm trying
> to figure out how to implement it, and the best/good approach to this.
> i'm actually considering integrating this kind of process within a cms
> (joomla/mambo/cmsms/etc..) but right now, this is in the initia
> thought stage...
>
> if you have a thought/page that i can lok at that's actually
> implementing this kind of flow.. i'd really like to see it..
>
> so, here goes...
>
> ===============================================
>
> --need to figure out a way to have the user invoke an action on the
> top section of
>  a page, and have that action, trigger an action on a separate part of the 
> page
>
>
> example:
>
> i have a page that looks something like this:
>
>  +---------------------------------------------------------------+
>
>     initial navbar stuff (always shown on the page)
>
>     <form name="foo">
>       stateList (select/option)
>     </form>
>
>
>     +----------------------------------+
>       <form name="cat"> based on the user
>         selected state                             {
>          <tbl name="dog"> based on the user        {  <<<<< based on
> the selected state
>           user state                               {
>                                                    {
>          "cancelBTN"  "submitBTN"
>       </form>
>
>     +----------------------------------+
>
>                                                        (page1)
>  +---------------------------------------------------------------+
>
> i need to have a way to have the user select a "state" from the
>  statelist, and to then have the tbl/section of the site under
>  the "cat" form, generated, based on the selected state.
>
> at the same time, i need a way to have the user select an item
>  from the "dog" tbl, and to have the user select the
>  cancelBTN/submitBTN, with the app then generating the
>  subsequent action/logic. the page below, is a kind of
>  example of what i'm thinking of...
>
>  +---------------------------------------------------------------+
>
>     initial navbar stuff (always shown on the page)
>
>     <form name="foo">
>       stateList (select/option)
>     </form>
>
>
>     +----------------------------------+
>       <form name="cat2"> based on the user
>         selected state, and the cat1.submitBTN
>
>          confirmation section
>                                                              {
>           based on the user selection from page1/cat1        { <<<
> based on the previous
>           cancel/submitBTN                                   {
> cancel/submitBTN
>
>          "cancelBTN"  "submitBTN"
>       </form>
>
>     +----------------------------------+
>
>                                                        (page2)
>  +---------------------------------------------------------------+
>
>
> i can see a couple of ways of accomplishing this...
>
> 1) i can have a page of logic, that is composed of a bunch of
>  logic, that is basically an "if block", that generates/displays
>  the different parts of the page, based on the user actions of
>  the preceding pages/sections (the cancel/submitBTNs). this approach
>  would essentially require the entire page to be regenerated with
>  each BTN selection.
>
>  the logic would generate/invoke the correct page elements based
>  on the user selection/action of the previous page/section.
>
> 2) i could possibly utilize div/frames, to allow the content in
>  the targeted div/frame to be updated/redrawn/regenerated based
>  on the user action/selection of the previous page/section...
>
>  this might be able to be done (not familiar with the
>  underlying processes to know if this is doable/suitable)
>  or even a goof approach..
>
>  would this apaproach still require the entire page to be
>  redrawn? or just the portion that's in the targeted
>  div/frame...
>
> 3) somehow invoke javascript/ajax function/features/logic,
>  to allow the actions/interaction to occur, such that the
>  content in the targeted div/frame is modified, without
>  requiring the rest of the page to be modified...
>
>  i have no idea if this is doable, or what this would mean,
>  or involve, or how to apprach this..
>
>
> or, there might be a different way of accomplishing this
>  that i haven't even thought of...
>
> any example sites/docs/code would be greatly appreciated...
> heck, i'd even be glad to see an actual site/code that
> demonstrates how this can/might/should be implemented!!!
>
>
> thoughts/comments...
>
> thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Has cli php changed recently?

I've got a php script (script1) that creates a php script (script2) by
opening a file and then writing to it. When I try to run it from the
command line script1 is simply copied to stdout. When I run it from the
browser it works as expected. The directory has 777 permissions so that
should not be the problem.

Any ideas?

-- 
"Whatever the immediate gains and losses, the dangers to our safety
arising from political suppression are always greater than the dangers
to that safety resulting from political freedom. Suppression is always
foolish. Freedom is always wise." -- Alexander Meiklejohn, 1955
    Rick Pasotto    r...@niof.net    http://www.niof.net

--- End Message ---
--- Begin Message ---
On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:

> Has cli php changed recently?
> 
> I've got a php script (script1) that creates a php script (script2) by
> opening a file and then writing to it. When I try to run it from the
> command line script1 is simply copied to stdout. When I run it from the
> browser it works as expected. The directory has 777 permissions so that
> should not be the problem.
> 
> Any ideas?
> 
> -- 
> "Whatever the immediate gains and losses, the dangers to our safety
> arising from political suppression are always greater than the dangers
> to that safety resulting from political freedom. Suppression is always
> foolish. Freedom is always wise." -- Alexander Meiklejohn, 1955
>     Rick Pasotto    r...@niof.net    http://www.niof.net
> 


How are you running it from the command line?

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



--- End Message ---
--- Begin Message ---
On Sun, Mar 14, 2010 at 06:13:24PM +0000, Ashley Sheridan wrote:
> On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:
> 
> > Has cli php changed recently?
> > 
> > I've got a php script (script1) that creates a php script (script2) by
> > opening a file and then writing to it. When I try to run it from the
> > command line script1 is simply copied to stdout. When I run it from the
> > browser it works as expected. The directory has 777 permissions so that
> > should not be the problem.
> > 
> > Any ideas?
> 
> How are you running it from the command line?

Is there more than one way? I suppose with and without the -f could
count as two ways, but the man page says without defaults to with so
they're really the same.

-- 
"Remember, today is the tomorrow you worried about yesterday."
        -- Dale Carnegie
    Rick Pasotto    r...@niof.net    http://www.niof.net

--- End Message ---
--- Begin Message ---
On Sun, 2010-03-14 at 16:41 -0400, Rick Pasotto wrote:

> On Sun, Mar 14, 2010 at 06:13:24PM +0000, Ashley Sheridan wrote:
> > On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:
> > 
> > > Has cli php changed recently?
> > > 
> > > I've got a php script (script1) that creates a php script (script2) by
> > > opening a file and then writing to it. When I try to run it from the
> > > command line script1 is simply copied to stdout. When I run it from the
> > > browser it works as expected. The directory has 777 permissions so that
> > > should not be the problem.
> > > 
> > > Any ideas?
> > 
> > How are you running it from the command line?
> 
> Is there more than one way? I suppose with and without the -f could
> count as two ways, but the man page says without defaults to with so
> they're really the same.
> 
> -- 
> "Remember, today is the tomorrow you worried about yesterday."
>       -- Dale Carnegie
>     Rick Pasotto    r...@niof.net    http://www.niof.net
> 


Well you havn't given an example, and just say you're calling the script
from command line and it's outputting the script there. Are you maybe
just calling the php file without calling php first?

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



--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:
> Wow.  Maybe the coolest IDE innovation I've seen since syntax highlighting
> and intellisense.
> 
>  <http://www.cs.brown.edu/people/acb/codebubbles_site.htm>
> http://www.cs.brown.edu/people/acb/codebubbles_site.htm
>  
> http://www.cs.brown.edu/people/acb/codebubbles_beta_signup.htm
>  Code Bubbles is built on top of Eclipse so it can open/work with any
> existing Eclipse project.
>  
> ...are you listening Zend? Someone needs to port this over for a PHP IDE
> (It's JAVA only AFAIK)
> 

great find! nice one

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

is there a FreeType extension that doesn't rely on
not-calling-freetype-in-the-slightest through GD? GD is lacking lots of
function wrappers for things that are part of the standard FreeType2 API,
like the super basic "get char index" function, which are essential for any
kind of intelligent text rendering, 

Is there a way to access FreeType directly, without going through GD? Or is
this going to end up being one of those "there's no way to do this, call an
exec() to something in python or perl instead" things?

- Mike Kamermans

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

I'm using the following code:
____________________
$fp      = fopen($filename, 'r+');
$content = fread($fp, 
filesize($filename));
fclose($fp);
header("Content-type: 
application/msword");
header("Content-Disposition: attachment; 
filename=$filename");
echo $content;
exit;
___________________

Now when downloading a file the default name that appears for the user is 
the realname of the file i the server with the real path the only 
difference is that the slashes are modified by underscore.

My 
question is: is there any way how to control the name that will be 
displayed for the customer? Or at least skip the path and display just 
the file's name?

Thank you


      __________________________________________________________________
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot 
with the All-new Yahoo! Mail.  Click on Options in Mail and switch to New Mail 
today or register for free at http://mail.yahoo.ca

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

Make a $new_filename and put that in the header:

$neW_filename = "downloadfile." . $filetype;
header("Content-Disposition: attachment; filename=$new_filename");
(the content of the file is now in $content, so if you like you could also change the value of $filename if you preferrer that)

You'll need to detect $filetype from $filename to always have the same filename as the original file.

/kim

Php Developer wrote on 14/03/2010 21:29:
Hi,

I'm using the following code:
____________________
$fp      = fopen($filename, 'r+');
$content = fread($fp, filesize($filename));
fclose($fp);
header("Content-type: application/msword"); header("Content-Disposition: attachment; filename=$filename");
echo $content;
exit;
___________________

Now when downloading a file the default name that appears for the user is the realname of the file i the server with the real path the only difference is that the slashes are modified by underscore.

My question is: is there any way how to control the name that will be displayed for the customer? Or at least skip the path and display just the file's name?

Thank you


      __________________________________________________________________
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot 
with the All-new Yahoo! Mail.  Click on Options in Mail and switch to New Mail 
today or register for free at http://mail.yahoo.ca


--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
You can set the name to display as you see fit, just change $filename
to your liking right before the header() call. If you just want to cut
the path, use basename($filename)

Regards
Peter

On 14 March 2010 21:29, Php Developer <pdevelo...@rocketmail.com> wrote:
> Hi,
>
> I'm using the following code:
> ____________________
> $fp      = fopen($filename, 'r+');
> $content = fread($fp,
> filesize($filename));
> fclose($fp);
> header("Content-type:
> application/msword");
> header("Content-Disposition: attachment;
> filename=$filename");
> echo $content;
> exit;
> ___________________
>
> Now when downloading a file the default name that appears for the user is
> the realname of the file i the server with the real path the only
> difference is that the slashes are modified by underscore.
>
> My
> question is: is there any way how to control the name that will be
> displayed for the customer? Or at least skip the path and display just
> the file's name?
>
> Thank you
>
>
>      __________________________________________________________________
> Be smarter than spam. See how smart SpamGuard is at giving junk email the 
> boot with the All-new Yahoo! Mail.  Click on Options in Mail and switch to 
> New Mail today or register for free at http://mail.yahoo.ca



-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>

--- End Message ---

Reply via email to