Need help adding a timestamp to my filename/variable


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a form/php setup that allows a user to upload an image to my server. The upload is working well, and the code is functioning as is, however, I would like to add a timestamp to the file name before it is saved to the server, as well as making sure the time stamped file name is turned into a variable I can recall on a later php page. This is all in an effort to create unique filenames for uploaded content.

Here is my current form code:

<FORM ENCTYPE="multipart/form-data" ACTION="uploadck.php" METHOD=POST>
Upload this file: <INPUT NAME="file_up" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File"></FORM>

and here is the php for that form:

<?
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
echo $_FILES[file_up][name];
if ($_FILES[file_up][size]>1000000){$msg=$msg."Your uploaded file size is more than 1MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
$file_upload="false";}

if (!($_FILES[file_up][type] =="image/jpeg" OR $_FILES[file_up][type] =="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";}

$file_name=$_FILES[file_up][name];
$add="upload/$file_name"; // the path with the file name where the file will be stored, upload is the directory name.
if($file_upload=="true"){

if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
echo "Congratulations, file succesfully uploaded";
}else{echo "Failed to upload file Contact Site admin to fix the problem";}

}else{echo $msg;}
?>

No comments posted yet

Your Answer:

Login to answer
254 Like 25 Dislike
Previous forums Next forums
Other forums

Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is

Setting/Modify Headers using mail() function
I have a question about setting email headers when using mail() in a php script.

When I send

How to separate records and ORDER BY
Let say i have 100 records and displayed in one page, then i want to get the records from 50-100 and

Help Ordering Arrays
Hi, I have 3 arrays as shown below.

Code: $users = $this->get_latest_users();
$flir

Echoing a Variable from a Object
How do I get a variable from the new User Class to echo out in this clasS?

class MyApp
{

Oracle Connectivity
Hi Every One,

Can we access SAP from oracle database.If it possible then please spec

pls clear my confusion
Hi friends,

Pls solve my query .

what is the exact use of Scope Resolution Operator( i

How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g

Ball movement
I want to move a ball from one point to another and it should hit a group of balls at the other end

Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash