close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Rename a file when uploading

Thread began 1/22/2019 7:36 am by María Luisa | Last modified 1/24/2019 1:44 pm by María Luisa | 153 views | 5 replies

María Luisa

Rename a file when uploading

I have the following form to upload files:
<form method="post" action="" name="FAIv1Pru" id="FAIv1Pru" enctype="multipart/form-data">

<div class="row" style="padding: 30px 0px;">
<!--fecha V1-->
<div class="col-sm-12" style="padding-bottom:20px;">
<label for="V1Date" style="color:#4437A3; font-weight:800;">Indicar fecha del vídeo 1</label>
<input type="text" class="form-control" name="V1Date" placeholder="aaaa-mm-dd" required>
<!--upload v1-->
<div class="col-sm-6" style="margin-top:30px;">
<div class="form-group">
<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
<label for="V1Pru" style="color:#4437A3; font-weight:800;">Subir vídeo Ensayo de Prueba</label>
<input type="file" name="V1Pru" id="V1Pru" accept="video/mp4,video/x-m4v,video/*" >
<!--upload cert 1-->
<div class="col-sm-6" style="margin-top:30px;">
<div class="form-group">
<label for="V1Cert" style="color:#4437A3; font-weight:800;">Subir certificado Ensayo de Prueba</label>
<input type="file" class="form-control-file" id="V1Cert" name="V1Cert" accept=".doc, .DOC, .docx, .DOCX">
<div class="clearfix"></div>
<div class="row" style="padding: 30px 0px;">
<div class="col-sm-12">
<input type="submit" value="Subir vídeo Ensayo de Prueba y su documentación" name="FAIV1" style="width:100%; background-color:#1837A3; color:#ffffff; padding:8px;">

I want to change the name of those files: users in Spain name their files using characters that are not valid in programming languages ​​such as "á" or "ñ".

I prepared the following script:

//SCRIPTS renombrar, para upload e insert
function replace_specials_characters($s) {
$s = preg_replace("/á|à|â|ã|ª/","a",$s);
$s = preg_replace("/Á|À|Â|Ã/","A",$s);
$s = preg_replace("/é|è|ê/","e",$s);
$s = preg_replace("/É|È|Ê/","E",$s);
$s = preg_replace("/í|ì|î/","i",$s);
$s = preg_replace("/Í|Ì|Î/","I",$s);
$s = preg_replace("/ó|ò|ô|õ|º/","o",$s);
$s = preg_replace("/Ó|Ò|Ô|Õ/","O",$s);
$s = preg_replace("/ú|ù|û/","u",$s);
$s = preg_replace("/Ú|Ù|Û/","U",$s);
$s = str_replace(" ","-",$s);
$s = str_replace("ñ","n",$s);
$s = str_replace("Ñ","N",$s);
$s = preg_replace('/[^a-zA-Z0-9_.-]/', '-', $s);
return $s;
//campo file: V1Pru
//boton: FAIV1
//form: FAIv1Pru
if(isset($_POST["FAIV1"]) && !empty($_FILES["V1Pru"]["name"])){
$dataV = date('Y-m-d');
$nombreVideo = replace_specials_characters($_FILES["V1Pru"]["name"]);
$nombreVideoBBDD = $dataV."_".basename($nombreVideo);
//campo file: docFAI
//boton: FAIV1
//form: FAIv1Pru
if(isset($_POST["FAIV1"]) && !empty($_FILES["V1Cert"]["name"])){
$data = date('Y-m-d');
$nombreDocumento = replace_specials_characters($_FILES["V1Cert"]["name"]);
$nombreDocBBDD = $data."_".basename($nombreDocumento);

My idea, taking as an example the upload of the video, is that the document uploads rename eliminating the special characters as it marks my function "replace_specials_characters" that I pick up in the variable "$nombreVideo".

My problem is to incorporate "$nombreVideo" to the process of renaming the file.

These are my scripts generated with WA:

// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "__02_video_pru/",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End?>

if(isset($_POST["FAIV1"]) || isset($_POST["FAIV1_x"])){
WA_DFP_UploadFiles("WA_UploadResult1", "V1Pru", "2", "$nombreVideo", "false", $WA_UploadResult1_Params);
}//Here I included the name of the variable $nombreVideo to rename
if (abs($WA_DFP_UploadStatus["WA_UploadResult1"]["statusCode"]) != 1) {
$WAFV_Redirect = "";
$_SESSION['WAVT_crearFAI2_506_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateNM($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["fileSize"] . "",0,52428800,""," ,",true,1);

if ($WAFV_Errors != "") {

But the fact is that it does upload the file, but does not rename it with the criteria "date_NameFileWithoutSpecialCharacters".

If anyone has any idea about how I can fix it, I appreciate it very much.

A greeting!

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...