1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

timestamp

Discussion in 'Software Development' started by mrsaywho, Mar 15, 2012.

Thread Status:
Not open for further replies.
  1. mrsaywho

    mrsaywho Thread Starter

    Joined:
    Mar 15, 2012
    Messages:
    1
    Does anyone know how to attach a timestamp to this code so when I upload the 4 images I get a timestamp.jpg? I have managed to have the image file in the folder get timestamped but not the path in mysql.
    HTML:
    <?php
    require_once('storescripts/connect.php');
    mysql_select_db($database_phpimage,$phpimage);
    $unique = strtolower(substr(md5(time()), 0, 4));	
    $uploadDir = 'upload/';
    
    if(isset($_POST['upload' . $config]))
    {
    foreach ($_FILES as $file)
    {
    
    $fileName = $file['name'];
    $tmpName = $file['tmp_name'];
    $fileSize = $file['size'];
    $fileType = $file['type'];
    
    if($fileName==""){
    
    $filePath = 'upload/';
    }
    else{
    
    $filePath = $uploadDir . $unique . $fileName;
    }
    
    $filePath = str_replace(" ", "_", $filePath);
    $result = move_uploaded_file($tmpName, $filePath);
    
    if(!get_magic_quotes_gpc())
    {
    $fileName = addslashes($fileName);
    $filePath = addslashes($filePath);
    }
    $fileinsert[]=$filePath;
    }
    }
    
    $mid   = mysql_real_escape_string(trim($_POST['mid']));
    $cat   = mysql_real_escape_string(trim($_POST['cat']));
    $item  = mysql_real_escape_string(trim($_POST['item']));
    $price = mysql_real_escape_string(trim($_POST['price']));
    $about = mysql_real_escape_string(trim($_POST['about']));
    
    $fields = array();
    $values = array();
    $updateVals = array();
    
    for($i=1; $i<=4; $i++)
    {
        $fields[$i] = 'name'.$i;
        $values[$i] = mysql_real_escape_string(basename(trim($_FILES[$fields[$i]]['name'])));
        if($values[$i] != '')
        {
            $updateVals[] = "{$fields[$i]} = '{$values[$i]}'";
        }
    }
    
    $updateNames = '';
    if(count($updateVals))
    {
    $updateNames =  ", " . implode(', ', $updateVals);
    }
    
    $update = "INSERT INTO image
                   (mid, cid, item, price, about, name1, name2, name3, name4)
               VALUES
                   ('$mid', '$cat', '$item', '$price', '$about', '$values[1]', '$values[2]', '$values[3]', '$values[4]')
               ON DUPLICATE KEY UPDATE
                    cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames";
    $result = mysql_query($update) or die (mysql_error());
    
    $id = mysql_insert_id();
    
    ?>
    <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; margin-left:25px;">Your Item Has Been Uploaded!</p>
    <script type="text/javascript">
    setTimeout('ourRedirect()', 2000)
    function ourRedirect() {
    	location.href='protator_php.php?mid=<?php echo $id ?>'
    }
    </script>
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1045242

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice