Results 1 to 7 of 7

Thread: Image Upload With Date (PHP)

  1. #1
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts

    Image Upload With Date (PHP)

    Hi,

    I have made a script to handle an image upload and want the date to be in front of the image name when uploaded but does not seem to put the date in front and just uploads the image without the date in front. But all the code looks fine to me. I think i have been looking at it for too long tbh and will be something very easy.

    PHP Code:

    $date 
    time("DMY",strtotime("now"));

    if(
    $_POST['action']=='Add Entry'){
        
    //handle image upload
        
    if(is_uploaded_file($_FILES['image']['tmp_name']) && move_uploaded_file($_FILES['image']['tmp_name'], './images/'.$_FILES['image']['name']) && $_FILES['image']['size']<(1024*100)){
            
    $imagefile './images/'.$date.$_FILES['image']['name'];
        } 

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    The time function does not accept any parameters. Check the PHP manual.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Indeed it doesn't take any parameters. It's the date() function which takes either one or two parameters.

    http://uk2.php.net/manual/en/function.date.php

    http://uk2.php.net/manual/en/function.time.php

  4. #4
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts
    Sorry i should have posted back i sorted this out the same day. It should have been:

    PHP Code:
    $date date("dmY",strtotime("now"));

    if(
    $_POST['action']=='Add Entry'){
        
    //handle image upload
        
    if(is_uploaded_file($_FILES['image']['tmp_name']) && move_uploaded_file($_FILES['image']['tmp_name'], './images/'.$date.$_FILES['image']['name']) && $_FILES['image']['size']<(1024*100)){
            
    $imagefile './images/'.$date.$_FILES['image']['name']; 

  5. #5
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    What are the contents of $date? Also, there's no need for the second parameter in the date function - if you want the time now, then you just leave out the second parameter i.e.

    $date = date("dmY")

    Unless, of course, that's supposed to be $now.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  6. #6
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    I'm assuming it works now?

    Also, it's usually best to include the seconds and/or milliseconds to make it more unique. It depends if it's for multiple users, because two users on the same day could upload an image with the same filename which would break it.

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Very good point Kezzer has made. Personally I would use a function such as flock - http://uk2.php.net/manual/en/function.flock.php
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mouse with a life of it's own.
    By firefox in forum PC Hardware and Components
    Replies: 10
    Last Post: 23-03-2006, 12:49 PM
  2. Image problems in IE (probably CSS related)
    By Dorza in forum Software
    Replies: 4
    Last Post: 08-05-2005, 11:50 PM
  3. Free Image Upload
    By ajbrun in forum General Discussion
    Replies: 1
    Last Post: 02-09-2004, 09:13 AM
  4. PHP image.
    By Nasimov in forum Software
    Replies: 3
    Last Post: 30-04-2004, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •