Shoutbox

PHP - filename editing on the fly. - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP - filename editing on the fly. (/showthread.php?tid=86758)

PHP - filename editing on the fly. by Nathan on 10-19-2008 at 10:33 PM

Okay so here's the situation.

Whenever I upload via the admin control panel, it will change the filename and change it to a random one that hasn't been used yet. This helps keep the site running smoothly with multiple admins.

Problem is, I get multiple emails a day of people saying the site is great but the random filenames are annoying.

I need to know of a fast and best possible way of changing the filename ON THE FLY, and supplying the user with the new filename.
So the user clicks download, it fetches "12345634hfd.zip" and then edits the filename to "Messenger.zip" and then they get the normal "are you sure you want to download this file - in firefox". Only way I can think of is fetching the file, saving it to another area and then changing the filename and then supplying the user with a new link - but this is slow and could cause errors if more than one person accessed at the same time.

I'm probs thinking too complicated for a simple thing, so maybe you could help me out :)

Thanks


RE: PHP - filename editing on the fly. by Mike on 10-19-2008 at 10:42 PM

mod_rewrite?


RE: PHP - filename editing on the fly. by Nathan on 10-19-2008 at 10:43 PM

How would that work? I have over 300 programs + skins that need to change on the fly...


RE: PHP - filename editing on the fly. by Eljay on 10-19-2008 at 10:46 PM

If you currently download it with PHP, e.g. content-disposition and not just a direct link:

header('Content-Disposition: attachment; filename="Messenger.zip"');


RE: PHP - filename editing on the fly. by ShawnZ on 10-19-2008 at 10:50 PM

header("Content-Disposition: attachment; filename=<whateverfilename>");

==

"You have chosen to open <whateverfilename> which is a <whatever type> from <your website>. Open With, Save File"


RE: PHP - filename editing on the fly. by Nathan on 10-19-2008 at 10:52 PM

I'll give you an idea of what I mean just before I try any of these methods (short on time, I have not alot of time to fiddle):

Say we go to:
http://www.touch-innovation.com/details-226-3/
And you go down, and click "Download" It will popup the box to save as and what not. How do I change it when they click there? (It goes via a download counter that edits the mysql db and then redirects to the file)


RE: PHP - filename editing on the fly. by Mike on 10-20-2008 at 05:24 AM

quote:
Originally posted by Nathan
How would that work? I have over 300 programs + skins that need to change on the fly...
Well, your upload script could automatically add a mod_rewrite entry on your .htaccess as soon as a file is uploaded. But this is a very bad solution because your .htaccess file will soon be filled with many entries, possibly making the server slower.

quote:
Originally posted by Nathan
It will popup the box to save as and what not
No it won't :P
It will redirect me to an external link.

Some other issues with the site too:
Text is cut off.
The resolution of the screenshot in the above link messes up the pictures aspect ratio :P

Also, remove that static background :(
It makes Firefox cry :cry:
RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 08:08 AM

Meh thats because you have a shitty resolution, it works okay for 1024x768 and upwards.

I'm recoding + redesigning it for the next update anyway, for the time being you can put up with it :P

Static background is fine on my firefox :S


BTW: I didn't give a very good example, this would be a better example:

http://www.touch-innovation.com/details-229-10/


RE: PHP - filename editing on the fly. by NanaFreak on 10-20-2008 at 08:10 AM

why not just make it go to a php file that has the random filename as a parameter then just do the header stuff to get it to download the file?

seems simple enough to me =\


RE: RE: PHP - filename editing on the fly. by ryxdp on 10-20-2008 at 09:05 AM

quote:
Originally posted by Nathan
Static background is fine on my firefox :S

use
background-attachment: scroll;

it makes scrolling a hell of a lot easier :P
RE: PHP - filename editing on the fly. by John Anderton on 10-20-2008 at 10:10 AM

offtopic: scrolling is kinda laggy but its fine. The background has no issues.

SOMEONE FUCKING FIX MY WIZARD SO I CAN GET TO WORK ON TOUCH INNOVATION :'(
* John Anderton runs back to studies for his on going exams :dodgy:


RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 10:13 AM

No, I want the background to stay in view at all time and not move and repeat... That's the desgin. Anyway were going off topic...

Help :p

EDIT: Thanks JA :P, yeah get it fixed whore :(


RE: PHP - filename editing on the fly. by thorerik on 10-20-2008 at 10:23 AM

as eljay said:
header('Content-Disposition: attachment; filename="Messenger.zip"');
should do the trick(as i use it on my own download script)


RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 03:11 PM

I currently use a header to fetch the file.
Basically when you click download it goes to the download page, which then fetches the id, and searches the db and finds relative results. It then headers it to the file (after adding +1 to the download counter).

So I tried using the Content-Disposition, but it doesn't work properly :S.

code:
header("Location: {$download}");


That's whats in my download page (minus the counter).

Help :P
RE: PHP - filename editing on the fly. by Dempsey on 10-20-2008 at 04:05 PM

code:
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="download.zip"');
readfile($download);

RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 05:52 PM

Yeah but not all of them are zip, this is the complication. It can be exe, cabs, zip, rars and the list goes on...

I tried that originally (what you posted dempsey).

Thanks though :)


RE: PHP - filename editing on the fly. by Lou on 10-20-2008 at 09:17 PM

quote:
Originally posted by Nathan
Yeah but not all of them are zip, this is the complication. It can be exe, cabs, zip, rars and the list goes on...

I tried that originally (what you posted dempsey).

Thanks though :)
You could very easily change that to use a variable, and grab the random file name, run it through the database, match with the new filename, output that, and bam.
RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 09:32 PM

I see, like explode() it to get the file extension, and then do it that way. Hmm I thought there would be an easier way :(

Ah well, looks like I'll be doing it like that. Unless anyone else wants to post a sollution?


RE: PHP - filename editing on the fly. by Eljay on 10-20-2008 at 09:44 PM

quote:
Originally posted by Nathan
I see, like explode() it to get the file extension

Or just use basename :P
RE: PHP - filename editing on the fly. by Nathan on 10-20-2008 at 09:54 PM

How would that work? If I want to just get the file extension and add a totally different filename :S

I'm confusing myself now :(


RE: PHP - filename editing on the fly. by hmaster on 10-21-2008 at 10:14 AM

code:
<?php
$file = "linktofile.ext"
$path = pathinfo($file);
$extension = $path['extension'];
$newfile = "NEWNAME.".$extension;

#then do the header code?
?>

RE: PHP - filename editing on the fly. by Mike on 10-21-2008 at 10:48 AM

quote:
Originally posted by Nathan
Meh thats because you have a shitty resolution, it works okay for 1024x768 and upwards.
I use 1024x768.
Scrolling is just way too slow.
RE: PHP - filename editing on the fly. by hmaster on 10-21-2008 at 11:45 AM

Mine is 1440x900 and it's still a bit choppy.


RE: PHP - filename editing on the fly. by Nathan on 10-21-2008 at 12:41 PM

Mines 1440x900 and it all depends on the gpu. My 8800gtx works fine with it.


RE: PHP - filename editing on the fly. by Mike on 10-21-2008 at 12:51 PM

quote:
Originally posted by Nathan
Mines 1440x900 and it all depends on the gpu. My 8800gtx works fine with it.
But not everyone's got an 8800...
RE: PHP - filename editing on the fly. by Nathan on 10-21-2008 at 02:58 PM

My intel gpu on this thing works fine with it as well :)


RE: PHP - filename editing on the fly. by Mike on 10-21-2008 at 10:40 PM

quote:
Originally posted by Nathan
My intel gpu on this thing works fine with it as well :)
Just try it on a computer that was bought on 2002 :P
RE: PHP - filename editing on the fly. by Nathan on 10-21-2008 at 10:41 PM

Okay, lol, we're going off topic, I might update it.

In the mean time, I need help with the PHP :P


RE: PHP - filename editing on the fly. by NanaFreak on 10-22-2008 at 03:20 AM

quote:
Originally posted by hmaster
code:
<?php
$file = "linktofile.ext"
$path = pathinfo($file);
$extension = $path['extension'];
$newfile = "NEWNAME.".$extension;

#then do the header code?
?>

what would work perfect... all you have to do is change the download page to go to that php page =\

[offtopic]
i have had to adblock the background image as the lag was so bad... nvidia 6200... not everyone has alot of money to buy a decent graphics card remember..
RE: PHP - filename editing on the fly. by ShawnZ on 10-22-2008 at 03:38 AM

uh, does graphics card really matter when websites aren't accelerated anyway :p


RE: PHP - filename editing on the fly. by Nathan on 10-24-2008 at 07:08 PM

So why does it work fine for some computers and not?

Anyway It's holidays now so I have no time lol - will wait till next week. But if you can post fixes I can quickly test them :P


RE: PHP - filename editing on the fly. by vaccination on 10-24-2008 at 07:17 PM

quote:
Originally posted by Nathan
So why does it work fine for some computers and not?

er, memory, cpu?
RE: PHP - filename editing on the fly. by Nathan on 10-24-2008 at 07:21 PM

Yeah, my mums old old laptop (90mhz cpu, 128mb of ram) runs it fine...


RE: PHP - filename editing on the fly. by Spunky on 10-25-2008 at 09:23 AM

quote:
Originally posted by Nathan
Yeah, my mums old old laptop (90mhz cpu, 128mb of ram) runs it fine...

As long as only you and her are the only ones that visit the site, you'll be OK then ;)
RE: PHP - filename editing on the fly. by -dt- on 10-25-2008 at 09:51 AM

quote:
Originally posted by Spunky
quote:
Originally posted by Nathan
Yeah, my mums old old laptop (90mhz cpu, 128mb of ram) runs it fine...

As long as only you and her are the only ones that visit the site, you'll be OK then ;)
pretty much a given
RE: PHP - filename editing on the fly. by Nathan on 10-25-2008 at 10:30 AM

Pfft, I get plenty of visitors every day, especially for a site that I don't add content anymore. I have admins that add content. I just check the admin panel occasionally for emails and such.

I just need this fucking thing fixing :P


RE: PHP - filename editing on the fly. by NanaFreak on 10-25-2008 at 12:31 PM

quote:
Originally posted by Nathan
I just need this fucking thing fixing :P
well we have given you something that will defiantly work...