Upload date gives me the file date not upload date

General discussions related to php

Moderators: macek, egami, gesf

chris122380
New php-forum User
New php-forum User
Posts: 30
Joined: Mon Jun 25, 2012 12:41 pm

Upload date gives me the file date not upload date

Postby chris122380 » Tue Jul 31, 2012 2:22 pm

I have created a upload form and php file to upload the file to a folder. Created a variable of

Code: Select all

$todaysDate = date("m_j_Y_"); // Todays date mm_dd_yyyy_


I then append the date to the file name.

Code: Select all

$newfile = $todaysDate.$name;


If I echo the $todaysDate it gives me today's date but if I echo $newfile it atatches the date that the file was created on or when it was last modified. I would like to know how to get the date the file is being uploaded or the date the script is being run on to attach to the file name and not the creation or modified date.

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Upload date gives me the file date not upload date

Postby freshnet » Tue Jul 31, 2012 4:45 pm

Please start by posting all of your code.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Upload date gives me the file date not upload date

Postby johnj » Tue Jul 31, 2012 7:32 pm

...file is being uploaded or the date the script is being run on to attach to the file name ....


Just before upload rename the file using the current date.

chris122380
New php-forum User
New php-forum User
Posts: 30
Joined: Mon Jun 25, 2012 12:41 pm

Re: Upload date gives me the file date not upload date

Postby chris122380 » Wed Aug 01, 2012 6:04 am

Index.html

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <title>Uploading files</title>
</head>
<body>
    <h1>Uploading files</h1>
    <hr><!-- Makes a Horizontal line accross the page-->
   
    <!-- Upload Form -->
    <form action='upload.php' method='post' enctype='multipart/form-data'>
       
        File: <input type='file' name='upload'>
        <input type='submit' name='submit' value='Upload File Now'>
       
    </form>
   
</body>
</html>
upload.php

Code: Select all

<?php

if($_POST['submit']){
   
    // Assign uploaded file information to Variables
    $name = $_FILES['upload']['name'];
    $temp = $_FILES['upload']['tmp_name'];
    $type = $_FILES['upload']['type'];
    $size = $_FILES['upload']['size'];
   
 // Validate variables   echo "$name<br />$temp<br />$type<br />$size";
   
    // File types allowed to be uploaded
    if(($type == 'application/pdf') || ($type == 'application/msword') || ($type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') || ($type == 'application/vnd.ms-excel') || ($type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || ($type == 'image/jpg') || ($type == 'image/jpeg')){
   
   
    //Limit file size to 30mb $size is the max file size alloud.
    if($size <= 31457280){
       
        // echo "The file: $name size is $size";
       
        $todaysDate = date("m_j_Y_"); // Todays date mm_dd_yyyy_
       
        //add the date to the begining of the file name.
        $newfile = $todaysDate.$name;
               
                // echo $newfile;
               
        move_uploaded_file($temp,"documents/$newfile");
       // echo "<img src='$newfile'>";
       $link = "<a href='documents/$newfile'>$newfile</a>"; //Places the upload as a link into a variable
       
       echo $link;
       
    }else{
       
        echo "The file: $name is to big....<br />The size is $size and need to be less than 30mb";
       
    }
   
   
   
    }else{
       
        echo "This type $type is not allowed";
       
    }
   
   
}else{
   
    header("Location: index.html");
   
}

?>

chris122380
New php-forum User
New php-forum User
Posts: 30
Joined: Mon Jun 25, 2012 12:41 pm

Re: Upload date gives me the file date not upload date

Postby chris122380 » Thu Aug 02, 2012 9:53 am

Problem went away after restarting my PHP server.


Return to “PHP General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest