Switch to full style
Dynamic open source server-side web development
Post a reply

Long files name

Mon Feb 09, 2009 2:25 pm

Hi,

I'm new here and still beginner to PHP need help to solve my problem to make shorten file name on PHP code as below :-
else {
$n = $_FILES[$name]["name"];
$rndName = md5($n . date("d-m-y") . time()) . "." . findExtension($n);
$uploadPath = "pictures/" . $rndName;
$tempPath = $_FILES[$name]["tmp_name"];
move_uploaded_file($tempPath, $uploadPath);
}

with above code the file name will be : seywbcnckdkfpzasmddldje9ie.jpg
if possible I need the file name will be shorten like amdnhs.jpg

Thanks in advance on any help.



Re: Long files name

Mon Feb 09, 2009 11:14 pm

you can name the uploaded file by the name you want ,,,
in the
Code:

$uploadPath 
"pictures/" $rndName;
 


Re: Long files name

Tue Feb 10, 2009 7:13 am

msi_333 wrote:you can name the uploaded file by the name you want ,,,
in the
Code:

$uploadPath 
= "pictures/" . $rndName;
 

Thanks for your great help, how to apply this change to be file name? :beg:
Can you give me step or simple for this change?

Re: Long files name

Wed Feb 11, 2009 12:20 am

In this line
Code:

$rndName 
md5($n date("d-m-y") . time()) . "." findExtension($n);
 


replace it for example

In this line
Code:

$rndName 
=   "example." findExtension($n);
 


So the file will be example.jpg

Re: Long files name

Wed Feb 11, 2009 1:32 am

I apply as your code example above I got a resulted for what I want it, but all files upload get the same name example.jpg, thanks

But it more nice if I can add a random string with numbers and letters at the end of each example files, eg: example_as12.jpg. Tried in many way but I got an error message, I think this is the last part of the code on applying to upload file with random string.

With your help on this random string all done for this code. thanks msi_333 for your great help. :beg:

Re: Long files name

Wed Feb 11, 2009 9:24 am

i don't think it is a good idea to use random function , because it can be repeated .

Re: Long files name

Wed Feb 11, 2009 9:38 am

With this code all files upload will override each others, that mean previous file with see with latest file upload.
Code:
$rndName =   "example." . findExtension($n);

Anyhow thanks for your help.

Re: Long files name

Thu Feb 12, 2009 10:02 pm

you are welcome :) .

Post a reply
  Related Posts  to : Long files name
 Sorry for long absence     -  
 String Too Long Exception     -  
 Get all files in folder     -  
 Merging JAR files     -  
 jar files commands     -  
 moving files in php     -  
 How to Load Files using JFileChooser!!     -  
 Image Files Generation     -  
 Print all files in a directory     -  
 ow do you get html files onto the internet?     -