Forums

Upload 2 files and rename them

teldrive 05 Mar, 2015
I have found very usefull to use php rename code of file upload action to rename a filename
<?php
return "newnamefile1";
?>

but my doubt is if it posible to do with 2 filenames
files config
file1:jpg
file2:jpg

arrayfields
file1,file2
php rename code
<?php
return "newnamefile1.jpg";
return "newnamefile2.jpg";
?>

but it doesnt work, it assign first name to both files, i think do I have to use two action?
teldrive 05 Mar, 2015
I fear in this case this is more complex question because is about to use the latest feature implemented in latest versión 5.08 that allows to rename a file that is uploaded , but so far I have only got with one file
Max_admin 10 Mar, 2015
Hi Teldrive,

The $file_name variable holds the clean field name, which means that you can use:

<?php
return "prefix".$file_name;


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 11 Mar, 2015
Hi Max, thanks for reply
the issue is when there is only one file to upload i can set
<?php  return "newnamefile1.jpg";   ?>
, we need in our application to know the namefile "newnamefile"
the issue is when there are 2 files and we want to use a fixed name for each, my question is regarding how can i detect
when file1 or file 2 are uploaded in order to set
<?php
 if(file1) return "newnamefile1.jpg";
if(file2) return "newnamefile2.jpg";
 ?>
Max_admin 11 Mar, 2015
This is not possible, its a static feature, you can't know which file is being uploaded, only the file name can be used.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 11 Mar, 2015
Maybe a new small addition can make this possible, please send me a message using the "contact us" page to try it!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 19 Mar, 2015
Answer
it works like a charm, thanks Max😀
here is my working code to upload 3 files and rename them to a fixed name(very useful if you setup parameters of a web page)
<?php
global $x;
if(!isset($x)){
$x = 1;
}else{
$x++;
}
switch ($x) {
    case 0:
        break;
    case 1:
       return "file1.jpg";
        break;
    case 2:
       return "file2.jpg";
        break;
    case 3:
       return "file3.jpg";
        break;
}
?>

[attachment=0]Captura.JPG[/attachment]
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger