FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


need urgent help plz !





salman_500
hey guyz...

welll i finally got my little automatic script working.... but there is one thing i wanted to modify... you see i have randim names for the files.... and i dont want to send the files to the users with that name... so is there any way i can rename the files before a user views em..

like i want the original name to be kept on my site.... like if a file is names 123.rar on my server....it remains the same...but once the client has downloaded the files...llike he saves it to the path... the name is not 123.rar.... but it has to be equal to 'name' column in the database of the row which has the id equal to the file name...

like in the above example... files name is 123.rar.. id in table is '123' but the name is ABC...

so i want is that once a user saves the file to a path... the file name on his computer is not 123....but ABC...


hope i clearified what i want...

thnx !
hexkid
Just change the name on the "Content-Disposition" header.
Code:
header('Content-Disposition: attachment; filename="ABC.rar"');


If the files are downloaded directly from Apache (with http://www.example.com/rand65091/rand735251/rand791028/123.rar for example), I don't think there's much you can do.
salman_500
hexkid wrote:
Just change the name on the "Content-Disposition" header.
Code:
header('Content-Disposition: attachment; filename="ABC.rar"');


If the files are downloaded directly from Apache (with http://www.example.com/rand65091/rand735251/rand791028/123.rar for example), I don't think there's much you can do.


ok this part works great...the file is renamed...... thnx !! Very Happy Very Happy

however..i wana know one more thing..... how can i get the extension from the database column "file" .... becaus my files may have diff extension...rar or zip or watever.... and that is stored in the file field.... e.g. "123.rar" is the value in the column "file"..

how can i do so that when its renamed... it renames to "ABC.rar" rather than only "ABC"

thnx ! Very Happy
kv
Code:


$ext = str_replace('.','',strstr($filename, '.'));

$abc="ABC";

$filename="$abc.$ext";

header('Content-Disposition: attachment; filename="$filename"');
hexkid
salman_500 wrote:
however..i wana know one more thing..... how can i get the extension from the database column "file" .... becaus my files may have diff extension...rar or zip or watever.... and that is stored in the file field.... e.g. "123.rar" is the value in the column "file"..

how can i do so that when its renamed... it renames to "ABC.rar" rather than only "ABC"
So you have `file` and `name` in the database.
When you fetch that specific record you get
Code:
$row['file'] = '123.rar';
$row['name'] = 'ABC';
and you want to come up with a variable containing "ABC.rar".

Do *all* your filenames have only a single dot? (Greasemonkey user scripts, for instance, are usually named USERSCRIPT.user.js)
How would you mix name="abc.def" and file="rand432190.user.js"?

Please provide unambiguous definitions for "filename" and "extension".

but why (!!!) do you save 123.rar to the database if the filename is ABC.rar? Twisted Evil
salman_500
hexkid wrote:
salman_500 wrote:
however..i wana know one more thing..... how can i get the extension from the database column "file" .... becaus my files may have diff extension...rar or zip or watever.... and that is stored in the file field.... e.g. "123.rar" is the value in the column "file"..

how can i do so that when its renamed... it renames to "ABC.rar" rather than only "ABC"
So you have `file` and `name` in the database.
When you fetch that specific record you get
Code:
$row['file'] = '123.rar';
$row['name'] = 'ABC';
and you want to come up with a variable containing "ABC.rar".

Do *all* your filenames have only a single dot? (Greasemonkey user scripts, for instance, are usually named USERSCRIPT.user.js)
How would you mix name="abc.def" and file="rand432190.user.js"?

Please provide unambiguous definitions for "filename" and "extension".

but why (!!!) do you save 123.rar to the database if the filename is ABC.rar? Twisted Evil



??? Confused ???

the only thing i asked for was what kv provided me with.....

welll since you asked... yes...all my files contain a single dot...

and the file column contains the complete file name "123.rar"...but the name field is only the name...so no extension or anything... "ABC" ... now i wanted it so that once a user downloaded the file.... it wouldn't reveal the real name of the file... and would just replace the filename by the name of the file...

so i used a database query to get the field comtaingin the name and file... now that i assigned the name as the new name for the file.. it came with no extension... so i wanted to get the extension from file column and add it to the new filename so that people wont have to "open with" or manually assign it a extension....

hope it clears it....

thnx for concern though ! Very Happy

and thnx kv !!!! Very Happy Very Happy
salman_500
hey..

sorry for double post... but i wanted to know somthing....

when you upload a file to a folder that does not exist...... how do we create that folder??

thnx !
hexkid
salman_500 wrote:
when you upload a file to a folder that does not exist...... how do we create that folder??


NOT TESTED
Code:
$newfile= '/path/with/inexistent/directory/file.zip';
mkdir(dirname($newfile), 0777, true);


Links:
http://php.net/dirname
http://php.net/mkdir

Warning: do not use URLs for $newfile
salman_500
hexkid wrote:
salman_500 wrote:
when you upload a file to a folder that does not exist...... how do we create that folder??


NOT TESTED
Code:
$newfile= '/path/with/inexistent/directory/file.zip';
mkdir(dirname($newfile), 0777, true);


Links:
http://php.net/dirname
http://php.net/mkdir

Warning: do not use URLs for $newfile


hey it works...thnx..

i had to remove ", true" from the code though.... because the error said that mkdir can use a max of 2 comands/or somthin......

thnx !

now how can i delete this folder ? Laughing Razz

thnx alot !!!

Cool Very Happy
hexkid
salman_500 wrote:
now how can i delete this folder ?

With rmdir(). Read the user comments for a solution when you want to remove a directory that is not empty.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.