php-general Digest 25 Sep 2009 11:52:57 -0000 Issue 6357
Topics (messages 298326 through 298349):
Re: variable
298326 by: Tommy Pham
298328 by: Tommy Pham
298329 by: Ben Dunlap
298330 by: Lars Nielsen
Re: session.gc_maxlifetime
298327 by: Ben Dunlap
html email showing <br> instead of line breaks
298331 by: Adam Williams
298332 by: Jonathan Tapicer
298333 by: Adam Williams
298335 by: Adam Williams
298336 by: Jonathan Tapicer
298338 by: Fernando Castillo Aparicio
298339 by: Ben Dunlap
RIGHT Function?
298334 by: sono-io.fannullone.us
298337 by: Tommy Pham
298340 by: Jay Blanchard
298341 by: Tommy Pham
298342 by: Tommy Pham
298343 by: sono-io.fannullone.us
298349 by: tedd
Downloader help needed :-(
298344 by: Chris Payne
298345 by: Tommy Pham
298346 by: Tommy Pham
298347 by: Chris Payne
Re: How to take output from an include, and embed it into a variable?
298348 by: Carl Furst
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: Grega Leskovšek <[email protected]>
> To: [email protected]
> Sent: Thursday, September 24, 2009 10:10:33 AM
> Subject: [PHP] variable
>
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
>
> Thanks in advance, Yours, Grega
>
>
> -- Peace refuge: http://users.skavt.net/~gleskovs/
> When the sun rises I receive and when it sets I forgive;) Grega Leskovšek
${'item'$i} ? Why not use array? Thus, $item[$i], simplify your life ;)
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Tommy Pham <[email protected]>
> To: Grega Leskovšek <[email protected]>; [email protected]
> Sent: Thursday, September 24, 2009 10:16:44 AM
> Subject: Re: [PHP] variable
>
> ----- Original Message ----
> > From: Grega Leskovšek
> > To: [email protected]
> > Sent: Thursday, September 24, 2009 10:10:33 AM
> > Subject: [PHP] variable
> >
> > Suppose I have a variable $i = 0 or 1 or 2
> > and I have variables $item0, $item1 and $item2
> > how do I print the variable $item0 using a combination of variable $item and
> > variable $i?
> > or with this code it gives me an error:
> > $i = 0;
> > $item0 = "test";
> > echo $item$i; #how do I properly use this variable $item with $i?
> >
> > Thanks in advance, Yours, Grega
> >
> >
> > -- Peace refuge: http://users.skavt.net/~gleskovs/
> > When the sun rises I receive and when it sets I forgive;) Grega Leskovšek
>
> ${'item'$i} ? Why not use array? Thus, $item[$i], simplify your life ;)
>
Typed too slow... my mistake. It should be:
${'item' . $i}
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
$var = "item$i";
echo $$var;
Note the two dollar-signs in the second line.
I wonder if a basic array would make for easier-to-read code, though:
$items = array( "test" );
$i = 0;
echo $items[$i];
Ben
--- End Message ---
--- Begin Message ---
Hi Grega
I think you might want to have a look at the array's section of the php
manual.
http://www.php.net/array
regards Lars
tor, 24 09 2009 kl. 19:10 +0200, skrev Grega Leskovšek:
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
>
> Thanks in advance, Yours, Grega
>
>
> -- Peace refuge: http://users.skavt.net/~gleskovs/
> When the sun rises I receive and when it sets I forgive;) Grega Leskovšek
--- End Message ---
--- Begin Message ---
> php not but perhaps the client its not clear and commonly defined what
> clients do with cookies on reconnect and stuff or long idle times.
Maybe not, but I'd be really surprised. An HTTP client is supposed to
decide whether to send a cookie by looking at the domain name and path
of the URL it's requesting. These things are at a totally different
layer from IP addresses -- and even if they weren't, in most cases I
would think a browser is going to be ignorant of public IP address
changes because it's going to be behind a NAT device.
> I would expect as source the new browsers where more and more users use
> subwindows to have concurrent sessions, does anybody know how they handle ip
> changes? I'm not.
What specific situation do you have in mind in which a browser would
even be aware of an IP change on the client side? Maybe there are
common cases I'm not thinking of.
Ben
--- End Message ---
--- Begin Message ---
I have users enter support tickets into a a <textarea> form and then it
emails it to me, I'm trying to get the emails to display when they hit
enter correctly, so i'm changing the \r\n to <br>, but in the email i'm
getting, its displaying the <br> instead of a line break: here is the code:
$message = "<html><head><title>new support request
#".mysqli_insert_id($mysqli)."</title></head><body><p>
Hello, ".$_SESSION["full_name"]." has created a new support request.
Please log in at <a href=\"http://intra/helpdesk\">MDAH Helpdesk</a>.
The problem request is \"";
$message .= htmlspecialchars(str_replace('\r\n', '<br>',
$_POST["problem"]));
$message .= "\" and the best time to contact is
\"".htmlspecialchars($_POST["contact_time"])."\" </p></body></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;
charset=iso-8859-1' . "\r\n";
$headers .= "From:
".$_SESSION["full_name"]."<".$_SESSION["username"]."@mdah.state.ms.us>"
."\r\n" .
"X-Mailer: PHP/" . phpversion();
mail('[email protected]', $subject, $message,
$headers);
but the email I get is:
Hello, Karen Redhead has created a new support request. Please log in at
MDAH Helpdesk <http://intra/helpdesk>. The problem request is "Elaine is
out today but her computer no longer has Past Perfect from what I can
tell. Also how does she access her email. The Sea Monkey email icon does
not take you anywhere.<br>Thanks so much,<br>Karen" and the best time to
contact is "1:30 -5:00"
How come the email is being displayed with <br> instead of line breaks?
--- End Message ---
--- Begin Message ---
\r\n should be between double quotes: "\r\n"
On Thu, Sep 24, 2009 at 3:52 PM, Adam Williams
<[email protected]> wrote:
> I have users enter support tickets into a a <textarea> form and then it
> emails it to me, I'm trying to get the emails to display when they hit enter
> correctly, so i'm changing the \r\n to <br>, but in the email i'm getting,
> its displaying the <br> instead of a line break: here is the code:
>
> $message = "<html><head><title>new support request
> #".mysqli_insert_id($mysqli)."</title></head><body><p>
> Hello, ".$_SESSION["full_name"]." has created a new support request.
> Please log in at <a href=\"http://intra/helpdesk\">MDAH Helpdesk</a>. The
> problem request is \"";
> $message .= htmlspecialchars(str_replace('\r\n', '<br>',
> $_POST["problem"]));
> $message .= "\" and the best time to contact is
> \"".htmlspecialchars($_POST["contact_time"])."\" </p></body></html>";
> $headers = 'MIME-Version: 1.0' . "\r\n";
> $headers .= 'Content-type: text/html; charset=iso-8859-1' .
> "\r\n";
> $headers .= "From:
> ".$_SESSION["full_name"]."<".$_SESSION["username"]."@mdah.state.ms.us>"
> ."\r\n" .
> "X-Mailer: PHP/" . phpversion();
> mail('[email protected]', $subject, $message, $headers);
>
> but the email I get is:
>
> Hello, Karen Redhead has created a new support request. Please log in at
> MDAH Helpdesk <http://intra/helpdesk>. The problem request is "Elaine is out
> today but her computer no longer has Past Perfect from what I can tell. Also
> how does she access her email. The Sea Monkey email icon does not take you
> anywhere.<br>Thanks so much,<br>Karen" and the best time to contact is "1:30
> -5:00"
>
>
> How come the email is being displayed with <br> instead of line breaks?
>
>
--- End Message ---
--- Begin Message ---
Thanks, i'll try that. what is the difference in using '' and ""? I
thought they were interchangeable.
Jonathan Tapicer wrote:
\r\n should be between double quotes: "\r\n"
--- End Message ---
--- Begin Message ---
oh nevermind, i see double quotes translate the \r\n to its appropriate
EOL character.
Adam Williams wrote:
Thanks, i'll try that. what is the difference in using '' and ""? I
thought they were interchangeable.
Jonathan Tapicer wrote:
\r\n should be between double quotes: "\r\n"
--- End Message ---
--- Begin Message ---
Double quotes accept special characters and string interpolation, see
the manual: http://php.net/manual/en/language.types.string.php
On Thu, Sep 24, 2009 at 4:00 PM, Adam Williams
<[email protected]> wrote:
> Thanks, i'll try that. what is the difference in using '' and ""? I
> thought they were interchangeable.
>
> Jonathan Tapicer wrote:
>>
>> \r\n should be between double quotes: "\r\n"
>>
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Have you tried http://es.php.net/manual/en/function.nl2br.php ?
I think it's easier and fits your needs.
________________________________
De: Adam Williams <[email protected]>
Para: PHP General list <[email protected]>
Enviado: jueves, 24 de septiembre, 2009 20:52:13
Asunto: [PHP] html email showing <br> instead of line breaks
I have users enter support tickets into a a <textarea> form and then it emails
it to me, I'm trying to get the emails to display when they hit enter
correctly, so i'm changing the \r\n to <br>, but in the email i'm getting, its
displaying the <br> instead of a line break: here is the code:
$message = "<html><head><title>new support request
#".mysqli_insert_id($mysqli)."</title></head><body><p>
Hello, ".$_SESSION["full_name"]." has created a new support request. Please
log in at <a href=\"http://intra/helpdesk\">MDAH Helpdesk</a>. The problem
request is \"";
$message .= htmlspecialchars(str_replace('\r\n', '<br>', $_POST["problem"]));
$message .= "\" and the best time to contact is
\"".htmlspecialchars($_POST["contact_time"])."\" </p></body></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' .
"\r\n";
$headers .= "From:
".$_SESSION["full_name"]."<".$_SESSION["username"]."@mdah.state.ms.us>" ."\r\n"
.
"X-Mailer: PHP/" . phpversion();
mail('[email protected]', $subject, $message, $headers);
but the email I get is:
Hello, Karen Redhead has created a new support request. Please log in at MDAH
Helpdesk <http://intra/helpdesk>. The problem request is "Elaine is out today
but her computer no longer has Past Perfect from what I can tell. Also how does
she access her email. The Sea Monkey email icon does not take you
anywhere.<br>Thanks so much,<br>Karen" and the best time to contact is "1:30
-5:00"
How come the email is being displayed with <br> instead of line breaks?
--- End Message ---
--- Begin Message ---
>>> \r\n should be between double quotes: "\r\n"
I think you'll still see the literal "<br>"s in your final email,
though because htmlspecialchars() is converting the angle-brackets in
the tag to their respective HTML entities ("<" for "<" and ">"
for ">").
A bit of a thorny problem because you probably do want to escape
HTML-characters in the message for security purposes. I suppose you
could call str_replace() after htmlspecialchars(), instead of before
it as you currently do.
OTOH, why not just send your email as plain text, instead of HTML?
Thanks,
Ben
--- End Message ---
--- Begin Message ---
Hi all,
I could use some help. I've scoured both the MySQL and PHP sites
that I know of and can't find an answer to this.
I have a price field that sometimes contains entries like this:
250,(min)
5.32
How can I pull just the price ($5.32 in this example) from this field
to display on a web page? Is there a RIGHT function in PHP? When I
search the PHP site, I'm being told there isn't one.
Here's the code I've been using:
<?php $result = mysql_query("SELECT priceList,unitprice FROM catalog
WHERE itemid='WR-1240'",$db);
printf('List: $%s<br />', number_format(mysql_result($result,
0,"priceList"),2));
printf('Your Price: $%s', number_format(mysql_result($result,
0,"unitprice"),2)); ?>
Thanks,
Frank
--- End Message ---
--- Begin Message ---
---- Original Message ----
> From: "[email protected]" <[email protected]>
> To: PHP General List <[email protected]>
> Sent: Thursday, September 24, 2009 12:01:41 PM
> Subject: [PHP] RIGHT Function?
>
> Hi all,
>
> I could use some help. I've scoured both the MySQL and PHP sites that I
> know of and can't find an answer to this.
>
> I have a price field that sometimes contains entries like this:
>
> 250,(min)
> 5.32
regex? If 250,(min)5.32 is in your row data, how do you sort price
ascending/descending?
>
> How can I pull just the price ($5.32 in this example) from this field to
> display on a web page? Is there a RIGHT function in PHP? When I search the
> PHP
> site, I'm being told there isn't one.
>
> Here's the code I've been using:
>
> > itemid='WR-1240'",$db);
> printf('List: $%s
', number_format(mysql_result($result,0,"priceList"),2));
> printf('Your Price: $%s',
> number_format(mysql_result($result,0,"unitprice"),2));
> ?>
>
> Thanks,
> Frank
>
> --PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
[snip]
I have a price field that sometimes contains entries like this:
250,(min)
5.32
How can I pull just the price ($5.32 in this example) from this
field
to display on a web page? Is there a RIGHT function in PHP? When I
search the PHP site, I'm being told there isn't one.
Here's the code I've been using:
[/snip]
substr will work from right to left.
If your data is in a variable do this;
echo substr($myData, -5);
Why -5? To account for 2 decimal places, the decimal and up to 99
dollars?
http://www.php.net/substr
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Jay Blanchard <[email protected]>
> To: [email protected]; PHP General List <[email protected]>
> Sent: Thursday, September 24, 2009 12:15:13 PM
> Subject: RE: [PHP] RIGHT Function?
>
> [snip]
> I have a price field that sometimes contains entries like this:
>
> 250,(min)
> 5.32
>
> How can I pull just the price ($5.32 in this example) from this
> field
> to display on a web page? Is there a RIGHT function in PHP? When I
> search the PHP site, I'm being told there isn't one.
>
> Here's the code I've been using:
> [/snip]
>
> substr will work from right to left.
>
> If your data is in a variable do this;
>
> echo substr($myData, -5);
>
> Why -5? To account for 2 decimal places, the decimal and up to 99
> dollars?
>
> http://www.php.net/substr
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Tommy Pham <[email protected]>
> To: PHP General List <[email protected]>
> Sent: Thursday, September 24, 2009 12:19:51 PM
> Subject: Re: [PHP] RIGHT Function?
>
> ----- Original Message ----
> > From: Jay Blanchard
> > To: [email protected]; PHP General List
> > Sent: Thursday, September 24, 2009 12:15:13 PM
> > Subject: RE: [PHP] RIGHT Function?
> >
> > [snip]
> > I have a price field that sometimes contains entries like this:
> >
> > 250,(min)
> > 5.32
> >
> > How can I pull just the price ($5.32 in this example) from this
> > field
> > to display on a web page? Is there a RIGHT function in PHP? When I
> > search the PHP site, I'm being told there isn't one.
> >
> > Here's the code I've been using:
> > [/snip]
> >
> > substr will work from right to left.
> >
> > If your data is in a variable do this;
> >
> > echo substr($myData, -5);
> >
> > Why -5? To account for 2 decimal places, the decimal and up to 99
> > dollars?
> >
> > http://www.php.net/substr
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> http://dev.mysql.com/doc/refman/5.1/en/string-functions.html
If you want to retain the ',(min)' for other uses, you'll have to do it in PHP
http://www.php.net/manual/en/ref.strings.php
stripos() and substr() will do it if you don't want to deal with/learn regex
--- End Message ---
--- Begin Message ---
On Sep 24, 2009, at 12:15 PM, Jay Blanchard wrote:
substr will work from right to left.
If your data is in a variable do this;
Thanks, Jay. That does the job.
Frank
--- End Message ---
--- Begin Message ---
At 12:33 PM -0700 9/24/09, [email protected] wrote:
On Sep 24, 2009, at 12:15 PM, Jay Blanchard wrote:
substr will work from right to left.
If your data is in a variable do this;
Thanks, Jay. That does the job.
Frank
Frank:
I came to this thread a little late, but the following are some
functions I use, namely right(), left() and mid(). These were
built-in functions in different language I used many years ago. They
just seemed natural to me so I wrote them for php.
Cheers,
tedd
-----
<?php
// ====== returns the right-most number of characters from a string
// $string = "123456789"
// right($string, 3) returns "789"
function right($string, $length)
{
$str = substr($string, -$length, $length);
return $str;
}
// ====== returns the left-most number of characters from a string
// $string = "123456789"
// left($string, 3) returns "123"
function left($string, $length)
{
$str = substr($string, 0, $length);
return $str;
}
// ====== returns the middle number of characters from a string
starting from the left
// $string = "123456789"
// mid($string, 3, 4) returns "4567"
function mid($string, $left_start, $length)
{
$str = substr($string, $left_start, $length);
return $str;
}
?>
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
HI everyone,
Thanks for those of you in the past that helped me with my downloader
not displaying the filename. Someone gave me a link to the downloader
below which works GREAT but i've tried and tried to limit the data
transfer to 60KB a second andI can't get it to work, can any of you
see what I could add to get it to work? The first peice of code the
code I WANT to use as it lets me download with the correct filename
etc ...... but the second piece of code allows me to limit the speed
of the transfer but when I try to merge the second with the first it
craps out on me.
Any help would REALLY be appreciated on this one.
Thanks everyone.
Piece of code 1 (Code I WANT to use)
function forceDownload($file) {
/**
* Function forceDownload:
* download any type of file if it exists and is readable
* -------------------------------------
* @author Andrea Giammarchi
* @date 18/01/2005 [17/05/2006]
* @compatibility PHP >= 4.3.0
*/
if(file_exists($file) && is_readable($file)) {
$filename = basename($file);
if(strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !==
false
&& strpos($filename, '.') !== false) {
$parsename = explode('.', $filename);
$last = count($parsename) - 1;
$filename = implode('%2E', array_slice($parsename, 0,
$last));
$filename .= '.'.$parsename[$last];
};
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;
filename="'.$filename.'"');
header('Content-Length:'.filesize($file));
header('Content-Transfer-Encoding: binary');
if(@$file = fopen($file, "rb")) {
while(!feof($file))
echo fread($file, 8192);
fclose($file);
};
exit(0);
};
};
Piece of code 2 (Which limits nice but has other issues)
$speed = 60; // i.e. 60 kb/s download rate
if(file_exists($file) && is_file($file)) {
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
//header("Content-Disposition: filename=$file" . "%20");
header("Content-Disposition: attachment; filename=\"$file\"");
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024)); // $speed kb at a time
flush();
sleep(1);
}
fclose ($fd);
}
Thank you everyone, it's really appreciated.
Chris
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Chris Payne <[email protected]>
> To: [email protected]
> Sent: Thursday, September 24, 2009 2:57:57 PM
> Subject: [PHP] Downloader help needed :-(
>
> HI everyone,
>
> Thanks for those of you in the past that helped me with my downloader
> not displaying the filename. Someone gave me a link to the downloader
> below which works GREAT but i've tried and tried to limit the data
> transfer to 60KB a second andI can't get it to work, can any of you
> see what I could add to get it to work? The first peice of code the
> code I WANT to use as it lets me download with the correct filename
> etc ...... but the second piece of code allows me to limit the speed
> of the transfer but when I try to merge the second with the first it
> craps out on me.
>
> Any help would REALLY be appreciated on this one.
>
> Thanks everyone.
>
> Piece of code 1 (Code I WANT to use)
>
> function forceDownload($file) {
> /**
> * Function forceDownload:
> * download any type of file if it exists and is readable
> * -------------------------------------
> * @author Andrea Giammarchi
> * @date 18/01/2005 [17/05/2006]
> * @compatibility PHP >= 4.3.0
> */
> if(file_exists($file) && is_readable($file)) {
> $filename = basename($file);
> if(strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !== false
> && strpos($filename, '.') !== false) {
> $parsename = explode('.', $filename);
> $last = count($parsename) - 1;
> $filename = implode('%2E', array_slice($parsename, 0, $last));
> $filename .= '.'.$parsename[$last];
> };
> header('Content-Type: application/octet-stream');
> header('Content-Disposition: attachment; filename="'.$filename.'"');
> header('Content-Length:'.filesize($file));
> header('Content-Transfer-Encoding: binary');
$speed = 60; // i.e. 60 kb/s download rate
> if(@$file = fopen($file, "rb")) {
> while(!feof($file))
{
// echo fread($file, 8192);
echo fread($fd, round($speed*1024)); // $speed kb at a time
flush();
sleep(1);
}
fclose($file);
> };
> exit(0);
> };
>
> };
>
> Piece of code 2 (Which limits nice but has other issues)
>
> $speed = 60; // i.e. 60 kb/s download rate
> if(file_exists($file) && is_file($file)) {
> header("Cache-control: private");
> header("Content-Type: application/octet-stream");
> header("Content-Length: ".filesize($file));
> //header("Content-Disposition: filename=$file" . "%20");
>
> header("Content-Disposition: attachment; filename=\"$file\"");
>
> flush();
> $fd = fopen($file, "r");
> while(!feof($fd)) {
> echo fread($fd, round($speed*1024)); // $speed kb at a time
> flush();
> sleep(1);
> }
> fclose ($fd);
> }
>
> Thank you everyone, it's really appreciated.
>
> Chris
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Try the above changes.
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Tommy Pham <[email protected]>
> To: [email protected]
> Sent: Thursday, September 24, 2009 4:19:48 PM
> Subject: Re: [PHP] Downloader help needed :-(
>
> ----- Original Message ----
>
> > From: Chris Payne
> > To: [email protected]
> > Sent: Thursday, September 24, 2009 2:57:57 PM
> > Subject: [PHP] Downloader help needed :-(
> >
> > HI everyone,
> >
> > Thanks for those of you in the past that helped me with my downloader
> > not displaying the filename. Someone gave me a link to the downloader
> > below which works GREAT but i've tried and tried to limit the data
> > transfer to 60KB a second andI can't get it to work, can any of you
> > see what I could add to get it to work? The first peice of code the
> > code I WANT to use as it lets me download with the correct filename
> > etc ...... but the second piece of code allows me to limit the speed
> > of the transfer but when I try to merge the second with the first it
> > craps out on me.
> >
> > Any help would REALLY be appreciated on this one.
> >
> > Thanks everyone.
> >
> > Piece of code 1 (Code I WANT to use)
> >
> > function forceDownload($file) {
> > /**
> > * Function forceDownload:
> > * download any type of file if it exists and is readable
> > * -------------------------------------
> > * @author Andrea Giammarchi
> > * @date 18/01/2005 [17/05/2006]
> > * @compatibility PHP >= 4.3.0
> > */
> > if(file_exists($file) && is_readable($file)) {
> > $filename = basename($file);
> > if(strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !== false
> > && strpos($filename, '.') !== false) {
> > $parsename = explode('.', $filename);
> > $last = count($parsename) - 1;
> > $filename = implode('%2E', array_slice($parsename, 0, $last));
> > $filename .= '.'.$parsename[$last];
> > };
> > header('Content-Type: application/octet-stream');
> > header('Content-Disposition: attachment; filename="'.$filename.'"');
> > header('Content-Length:'.filesize($file));
> > header('Content-Transfer-Encoding: binary');
>
> $speed = 60; // i.e. 60 kb/s download rate
>
> > if(@$file = fopen($file, "rb")) {
> > while(!feof($file))
> {
> // echo fread($file, 8192);
> echo fread($fd, round($speed*1024)); // $speed kb at a time
Sorry, still not wide awake from my afternoon nap...
The above should read:
echo fread($file, round($speed*1024)); // $speed kb at a time
> flush();
> sleep(1);
> }
> fclose($file);
>
> > };
>
>
> > exit(0);
> > };
> >
> > };
> >
> > Piece of code 2 (Which limits nice but has other issues)
> >
> > $speed = 60; // i.e. 60 kb/s download rate
> > if(file_exists($file) && is_file($file)) {
> > header("Cache-control: private");
> > header("Content-Type: application/octet-stream");
> > header("Content-Length: ".filesize($file));
> > //header("Content-Disposition: filename=$file" . "%20");
> >
> > header("Content-Disposition: attachment; filename=\"$file\"");
> >
> > flush();
> > $fd = fopen($file, "r");
> > while(!feof($fd)) {
> > echo fread($fd, round($speed*1024)); // $speed kb at a time
> > flush();
> > sleep(1);
> > }
> > fclose ($fd);
> > }
> >
> > Thank you everyone, it's really appreciated.
> >
> > Chris
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Try the above changes.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hi there,
Thank you Tommy, I will look at this when my little 3 year old devil
is in bed, I appreciate your help :-)
Chris
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Ashley Sheridan wrote:
On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
Mert Oztekin wrote:
Output buffering will do it.
Also I am not sure but did you try retrieving content with fopen() ?
Something like
$file = 'invoicetable_bottom.php';
fopen("http://yoursite.com/folder/$file","r");
http://tr.php.net/function.fopen
worth trying. Easier than output buffering
This would not work. fopen would open the file for read. What you would be
reading is the actual source of the document. Not the data the script would
output when ran.
The ob_* functions are the only way that I know of to do what you are asking
-----Original Message-----
From: Puiu Hrenciuc [mailto:[email protected]]
Sent: Wednesday, September 23, 2009 1:36 PM
To: [email protected]
Subject: [PHP] Re: How to take output from an include, and embed it into a
variable?
Hi,
The simplest way (actually the single way I know :) ) would be to
capture the output using output buffering functions, something like this:
// start output buffering
ob_start();
// include the file that generates the HTML (or whatever content)
include "....";
// get output buffer content
$output=ob_get_contents();
// clean output buffer and stop buffering
ob_end_clean();
// the content generated in the included file is now in $output variable
// use it as you consider fit
.........
Regards,
Puiu
Rob Gould wrote:
I have an invoice table that is drawn on a number of pages, so I have
all the logic in an include-file like this:
include "invoicetable_bottom.php";
However, now I'm needing to take the output from that include file and
pass it as an email. To do that, I need to somehow take the output from
this include file and get it into a variable somehow. Is there a simple
way to do this?
Something like: $emailtcontent = include "invoicetable_bottom.php"?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
That's just crazy talk. If you use fopen on a web URL, then it will
always return the output the script generates. That's how http works!
Sorry, my bad. Ash is correct, the method that is suggested will work. But you
will need to enable options in your php.ini that are not on by default for
security reasons, plus as Ben points out, you will need to filter out the scruff
that is generated to capture just the data output from your include.
Mind you that all of this also requires that the file that you are including is
accessible via the web. It could be in a folder that is not web accessible.
Sorry for the initial confusion!
Thanks,
Ash
http://www.ashleysheridan.co.uk
Do you have php configured to compile files? Why not just backtick the
php -f command??
<?
$cmd = *escapeshellcmd*("/full/path/to/php -f $file");
$email_output = `$cmd`;
# do something with $email_output
?>
Seems easier than a whole http call.. can be risky if the $file variable
can be set by user input (big no no), but other than that.. seeems the
simplest.
--- End Message ---