Hi. This last post didn't work /mby its old and there have been updates/ but it was very helpfull. I'm not a coder, but with some luck and most by guessing I got sucsess. I made it possible to change pics name.. Also when upload new pics in empty gallery they are named 01.jpg 02.jpg and etc. Then if u upload new pics in same gallery it checks the number of files in DIR and also checks the max number of file in DIR and starts the new uploaded image count from the biggest+1 of these two.. i did this to prevent overwriting of images.. if some pics are deleted, or some pics have text names.. couse u can change them with A, B, C if u want...
Here are my changes: /make backup.. i'm not PRO and can't guarantee/
Edit in administrator/components/com_sigpro/controllers/gallery.php, in public function save(), you will see a bunch of set state statements...add lines
$newfilenames = JRequest::getVar('newfilenames');
$model->setState('newfilenames', $newfilenames);
Then, in administrator/components/com_sigpro/models/gallery.php, around line 114, in public function upload(), before the line $result = JFile::upload($file, $path.'/'.$folder.'/'.JFile::makeSafe($filename)); add this:
$max = 0;
$directory = $path.'/'.$folder.'/';
if (($dir = opendir($directory)) !== false)
{
while (($filenam = readdir($dir)) !== false)
{
$int = intval(basename($filenam));
if ($int > $max)
{
$max= $int;
}
}
closedir($dir);
}
$filecount = count(glob($directory . "*"));
$filename = $max + 1;
if ($filecount>$filename ) {$filename = $filecount;}
if(strlen($filename)==1){$filename="0".$filename;}
$filename .=".jpg"; Important.. only for uploading JPG pictures.. ned some changes if u want to upload diferent types of images.
In same file some lines down is public function save().. here in function add:
$newfilenames= $this->getState('newfilenames');
and also some lines down replace the whole foreach ($files as $key => $file) with:
foreach ($files as $key => $file){
if ($newfilenames[$key] != strtok(pathinfo($file, PATHINFO_FILENAME), '-') ) {
if(strlen($newfilenames[$key])==1){$newfilenames[$key]="0".$newfilenames[$key];}
$character_array = array_merge(range(a, z), range(0, 9));
$string = "";
for($i = 0; $i < 6; $i++) {
$string .= $character_array[rand(0, (count($character_array) - 1))];
}
$newfilenames[$key] .= "-" .$string;
rename($path.'/'.$folder.'/'.$file, $path.'/'.$folder.'/'.$newfilenames[$key].'.jpg' );
}
}
In administrator/com_sigpro/views/gallery/tmpl/default.php, you'll see the spot where you can edit the image descript. and title...add this over title field:
<label>Filename</label>
<input type="text" name="newfilenames[]" value="<?php echo intval(strtok(pathinfo($image->name, PATHINFO_FILENAME), '-'));
I use pathinfo to get rid of .jpg and so i cant accidently delete image type which removes it from gallery - we add this .jpg in public save function.
And finaly in same file.. some lines down.. we need to ad the Filename field also for the fresh uploaded pics. Again over title field add this
<label>Filename</label>
<input type="text" class="sigProFilename" name="newfilenames[]" value=""/>
Here i could not remove .jpg from file name, but i didnt try much because if u refresh page or hit save button it removes .jpg and then u can easyly rearenge files....
Many thanks to
Matthew Cowan
Sorry if my english or code language is bad!
Hope i didnt forgot some line :) .. ..
And agan i'm not a coder, and there are mby lots of mistakes.. so make backups befor u try it.. or if u can rewrite it and post it here.. it works for me great for the moment :)
Ops.. i found BUG.. reordering not working corectly.. Pictures was overriding one another.. it was logical :) so I add unique random key to file name separated by "-" so i can extract and show from filename only the number infront. Code is fixed.. .