Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 5:28 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 8 posts ] 
Author Question
 Question subject: Long files name
PostPosted: Mon Feb 09, 2009 2:25 pm 
Offline
Newbie
User avatar

Joined: Mon Feb 09, 2009 1:52 pm
Posts: 5
Has thanked: 0 time
Have thanks: 0 time

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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Mon Feb 09, 2009 11:14 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
you can name the uploaded file by the name you want ,,,
in the
Code:

$uploadPath 
"pictures/" $rndName;
 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Tue Feb 10, 2009 7:13 am 
Offline
Newbie
User avatar

Joined: Mon Feb 09, 2009 1:52 pm
Posts: 5
Has thanked: 0 time
Have thanks: 0 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?


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Wed Feb 11, 2009 12:20 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Wed Feb 11, 2009 1:32 am 
Offline
Newbie
User avatar

Joined: Mon Feb 09, 2009 1:52 pm
Posts: 5
Has thanked: 0 time
Have thanks: 0 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:


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Wed Feb 11, 2009 9:24 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
i don't think it is a good idea to use random function , because it can be repeated .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Wed Feb 11, 2009 9:38 am 
Offline
Newbie
User avatar

Joined: Mon Feb 09, 2009 1:52 pm
Posts: 5
Has thanked: 0 time
Have thanks: 0 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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Long files name
PostPosted: Thu Feb 12, 2009 10:02 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
you are welcome :) .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 8 posts ] 
Quick reply


  

 Similar topics
 Uplading Files Dynamically Using SSIS
 script for including files
 How to download and save .mov files from this website ?
 How to read string text in files
 How to write a PHP coding to list out all files and director
 show all files in a directory with detail
 Working with menus, Label links and files in C#
 Accessing files in remote server (unix/windows) using JSP
 Get all files in folder
 print all files names in folder

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team