Reply
Unique file name using time?
Old 05-31-2008, 09:00 PM Unique file name using time?
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Okay in the following php code I need to modify it so that this part is unique.
Code:
/home/forbushj/www/video.flv
How do I make the Id unique using time?
so
theuniquename.flv
theuniquename.jpg so they have the same unique name? but one jpg the other flv meaning I could use them for the same purpose.

<?php
//home/forbushj/www/vidtemp/
$target = "vidtemp/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo
"Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if (!($uploaded_type=="video/x-ms-asf")) {
echo
"You may only upload movies.<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo
"Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
//COnvert the video
//echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
exec('ffmpeg -i '. basename( $_FILES['uploadedfile']['name']).' -ar 22050 -ab 32 -f flv -s 320x240 /home/forbushj/www/video.flv');
}
else
{
echo
"Sorry, there was a problem uploading your file.";
}
}
?>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
When You Register, These Ads Go Away!
Old 05-31-2008, 10:28 PM Re: Unique file name using time?
wayfarer07's Avatar
$frontend->developer

Posts: 1,036
Name: Abel Mohler
Location: Asheville, North Carolina USA
Something like this should work:
PHP Code:
date('Y.m.d.H.i.s.u'); 
That will return a date with a four digit year, two digit month, two digit day, 24 hour number, minutes, seconds, and milliseconds, all separated by a period. You can concatenate that to the end of anything to make a completely unique name that will never repeat.
__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is offline
Reply With Quote
View Public Profile
 
Old 06-01-2008, 11:56 AM Re: Unique file name using time?
Novice Talker

Posts: 7
Name: Nitin
Location: INDIA
Do this:

$target .= date("Y-m-d-H-i-s")

You also have to take care of file extension.

for that, 1. Seprate 'extension' 2. then, also concatenate this extension to $target

Last edited by nitin44u : 06-01-2008 at 11:58 AM.
nitin44u is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Unique file name using time?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12715 seconds with 12 queries