php-general Digest 7 Sep 2009 04:40:50 -0000 Issue 6326
Topics (messages 297744 through 297750):
File download question
297744 by: Chris Payne
297745 by: Jonathan Tapicer
297746 by: Andrea Giammarchi
Sorting an array of sub-arrays based on a sub-array's key
297747 by: James Colannino
297748 by: Eddie Drapkin
297749 by: James Colannino
Displaying image paths with spaces
297750 by: Skip Evans
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 ---
Hi Everyone,
I've setup a filedownload which works but i'm having an issue, i've
left out but when it downloads it, while it has the correct file it
doesn't have a file extension associated with it, I need the .7z
extension associated with the filename, can anyone see why that would
do this below?
I'm sure it's something obvious but i'm new to doing file downloads.
Thank you everyone
Chris
$file = "SOMEFILE.7Z";
$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");
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024)); // $speed kb at a time
flush();
sleep(1);
}
fclose ($fd);
}
--- End Message ---
--- Begin Message ---
I think that your problem in this line:
header("Content-Disposition: filename=$file" . "%20");
I don't know what that %20 is for and you should quote the filename,
that line should be something like this:
header("Content-Disposition: attachment; filename=\"$file\"");
Considering that $filename already has the 7z extension.
Jonathan
On Sun, Sep 6, 2009 at 3:19 PM, Chris Payne<[email protected]> wrote:
> Hi Everyone,
>
> I've setup a filedownload which works but i'm having an issue, i've
> left out but when it downloads it, while it has the correct file it
> doesn't have a file extension associated with it, I need the .7z
> extension associated with the filename, can anyone see why that would
> do this below?
>
> I'm sure it's something obvious but i'm new to doing file downloads.
>
> Thank you everyone
>
> Chris
>
> $file = "SOMEFILE.7Z";
> $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");
> flush();
> $fd = fopen($file, "r");
> while(!feof($fd)) {
> echo fread($fd, round($speed*1024)); // $speed kb at a time
> flush();
> sleep(1);
> }
> fclose ($fd);
> }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
That is for IE and its silly FileName[N] rather than FileName
here a good old function to download:
http://www.devpro.it/code/72.html
Regards
> Date: Sun, 6 Sep 2009 15:43:27 -0300
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> Subject: Re: [PHP] File download question
>
> I think that your problem in this line:
>
> header("Content-Disposition: filename=$file" . "%20");
>
> I don't know what that %20 is for and you should quote the filename,
> that line should be something like this:
>
> header("Content-Disposition: attachment; filename=\"$file\"");
>
> Considering that $filename already has the 7z extension.
>
> Jonathan
>
>
> On Sun, Sep 6, 2009 at 3:19 PM, Chris Payne<[email protected]>
> wrote:
> > Hi Everyone,
> >
> > I've setup a filedownload which works but i'm having an issue, i've
> > left out but when it downloads it, while it has the correct file it
> > doesn't have a file extension associated with it, I need the .7z
> > extension associated with the filename, can anyone see why that would
> > do this below?
> >
> > I'm sure it's something obvious but i'm new to doing file downloads.
> >
> > Thank you everyone
> >
> > Chris
> >
> > $file = "SOMEFILE.7Z";
> > $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");
> > flush();
> > $fd = fopen($file, "r");
> > while(!feof($fd)) {
> > echo fread($fd, round($speed*1024)); // $speed kb at a time
> > flush();
> > sleep(1);
> > }
> > fclose ($fd);
> > }
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
--- End Message ---
--- Begin Message ---
Hey everyone. I have an array that looks like this:
$main_array[0] = array('key1' => 'vala');
$main_array[1] = array('key1' => 'valb');
etc.
I want to sort the main array based on the value of key1 for each
sub-array. I looked at all the array sorting functions, but unless I
misunderstood something, I didn't see a direct way to do what I want.
If there were a sorting function in which I could pass as an argument
the name of a function that compares two elements like qsort in C, I
could do it easily. Is there a function like that in PHP? If not, what
should I do?
Thanks everyone!
James
--- End Message ---
--- Begin Message ---
On Sun, Sep 6, 2009 at 6:45 PM, James Colannino<[email protected]> wrote:
> Hey everyone. I have an array that looks like this:
>
> $main_array[0] = array('key1' => 'vala');
> $main_array[1] = array('key1' => 'valb');
> etc.
>
> I want to sort the main array based on the value of key1 for each
> sub-array. I looked at all the array sorting functions, but unless I
> misunderstood something, I didn't see a direct way to do what I want.
>
> If there were a sorting function in which I could pass as an argument
> the name of a function that compares two elements like qsort in C, I
> could do it easily. Is there a function like that in PHP? If not, what
> should I do?
>
> Thanks everyone!
> James
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
http://us3.php.net/uasort
--- End Message ---
--- Begin Message ---
Eddie Drapkin wrote:
> http://us3.php.net/uasort
Exactly what I was looking for. Thanks.
James
--- End Message ---
--- Begin Message ---
Hey all,
I have a CMS system that uses the FCKeditor to allow users to
create directories in which to store images. FCK allows users
to create directories with spaces in them, and it's pretty
deep in the JavaScript code so modifying that is not a simple
option, so at this point I'm trying to work from the
assumption that the users will continue to be allowed to
create directory names with spaces.
All that said, the CMS outputs data in two ways. I'll start
with the second method because it works and then move on to
the problem.
What the user has created in the FCKeditor is a path to an
image that appears like this:
src="/clients/client_118/images//Event%20images/Show%20ads/catspaw1compressed.jpg"
Notice the '%20' codes for the spaces in the directory names
like 'Event images' and 'Show ads'.
The first way the code is displayed is with an AJAX call. It's
read on the PHP side, echo'd back out to the JavaScript code
and inserted into an ID with an innerHTML assignment. This
method works.
The first way the code is loaded is pure PHP. It's read from
the database just as it appears above and then echo'd back to
the browser. However, in the browser it appears like this:
/clients/client_118/images//Event\ images/Show\
ads/catspaw1compressed.jpg
And of course the browser can't display the image with those
'\ ' combinations.
So my task is to get it to display the image properly on the
pure PHP side the same way it does via the AJAX call.
I should also say that the code the image path resides in
contains a text, etc, so it's a block of content, containing
both text and image paths.
Is there a way to read and echo this on the PHP side and
preserve a properly displayable path like the AJAX call, but
that also won't interfere with the rest of the HTML and text
code contained within the block of content?
I'm stumped on this one, so any help would be greatly,
wonderfully, blissfully even....... appreciated.
Thanks,
Skip
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--- End Message ---