Total members 11892 |It is currently Fri Sep 20, 2024 9:32 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 :-
Quote:
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.




Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

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

$uploadPath 
"pictures/" $rndName;
 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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?


Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

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

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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:


Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

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

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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.


Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

you are welcome :) .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 8 posts ] 

  Related Posts  to : Long files name
 Sorry for long absence     -  
 String Too Long Exception     -  
 jar files commands     -  
 moving files in php     -  
 Get all files in folder     -  
 Merging JAR files     -  
 Print all files in a directory     -  
 ow do you get html files onto the internet?     -  
 script for including files     -  
 Servlets how to upload Files     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com