Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Need Help with: Renaming file if picture already exists

    Hi there,
    Need some help with this code :
    I'm using this one for upload
    function Upload_GenFilename($filename, $tag, $filecounter = NULL)
    {
    $filedate = bqSearch;

    mt_srand();
    $randomnumber = mt_rand(1, 20);


    if(stristr($filename,$tag))
    {
    $filename = substr($filename,0,strlen($filename)-strlen($tag)-1);
    }

    //Neuer Filename
    if($filecounter == NULL)
    {
    $newfilename = $filename.'_'.$filedate.'.'.$tag;
    }

    else
    {
    $newfilename = $filename.'_'.$randomnumber.'_'.$filedate;
    }
    return $newfilename;

    If a user decided to delete a picture ,for example _7_picture.jpg and upload a new one, the picture should be renamed with the same title as the deleted one or a free one in this range 1 - 20.
    So i need to replace this one :

    //if picture already exists
    if(file_exists(JPath::clean(JPATH_ROOT.DS.$config->jg_pathimages.$catpath.$newfilename)))
    {
    $debugoutput .= JText::_('JGS_ALERT_SAME_PICTURE_ALREADY_EXIST');
    continue;
    }
    with :
    I need help here
    Many thanks in advance

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I would use a date prefix on the image uploads.

    2010_02_10_051618_image.jpg

    PHP Code:
    $image_prefix date("Y_m_d_his"); 


    -------------
    Leonard Whistler

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    But i need the exact title

    I need the exact title name ,cause i'm using it in another script.

    Every user uploads a file in his own dir. and i have to restrict the file titles to title1_10.jpg


  •  

    Posting Permissions

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