...

View Full Version : Need Help with: Renaming file if picture already exists



delxy
01-31-2010, 07:20 PM
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 :)

Len Whistler
01-31-2010, 11:01 PM
I would use a date prefix on the image uploads.

2010_02_10_051618_image.jpg


$image_prefix = date("Y_m_d_his");



-------------

delxy
01-31-2010, 11:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum