This topic is locked

How Change the name of file upload

1/10/2009 2:25:24 PM
PHPRunner General questions
A
Aleix author

Hello! I am starting in PHPRunner, in PHP in anything. I need help for do it.
How I can change the name of the file that I want upload?
I have a "File" Field. In that field I upload one file. I do it that from Add page.
I want change the name that I upload and store in DDBB
I use this code in Event "Before record added"
____

____

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair

//** ****
foreach($values as $field=>$value)

$message.= $field." : ".$value."
";

echo($message);
//Change the value of the name of the file that I want save

$values ["FILE"] = "XXX.DOC";
// I want to see if the value is changed. And it is changed ok.

foreach($values as $field=>$value)

$message.= $field." : ".$value."
";

echo($message);
return true;
// return true if you like to proceed with adding new record

// return false otherwise
------------------------------------------------------------------------------------------------
But the value save in the DDBB is changed, but the name of the file it is not changed.
In anohter hand if I write another name in the box "Filename" ( in the Add page") then change the name of the field stored and the name stored in the DDBB
I am thinking that there are another variable in HTML and it saves the file with this name. But I don´t know!
How I can change the name of the file that I want upload?
Table Foto

Field1 --> FOTO1 It is a Image field ( VARCHAR (50) )

Field2 --> FICHERO It is a File field ( VARCHAR (50) )
PHPRUNNER 5.0 BUILD 766
Thanks

J
Jane 1/13/2009
A
Aleix author 1/17/2009

Hi,

please check this thread:

http://www.asprunner.com/forums/index.php?showtopic=9357


Hello Jane;
I am happy becouse with your answer I konw it is possible! And it is very important. Thanks Jane
I have tried the code but it does not work to me.
This is the code I have tried
//****



function BeforeAdd(&$values,&$message,$inline)

{

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair

//****



//See $values

echo ("----------------values---- " ."
");

foreach($values as $key=>$value)

$message.= "Inidce= " .$key ." " .$value."
";

echo($message);
//------------------------------------------------------------------------------------- This is your code

global $files_move;
echo ("----------------files_move---- " ."
");

foreach( $files_move as $key=>$val)

{

// See $files_move

echo ("Indice= " .$key ."; Valor= " .$val ."
");
//if($val[0]==$_FILES["file_FieldName"]["tmp_name"]) -------- This is your line

if($val[0]==$_FILES["newFileName"]["tmp_name"])
//--- $files_move[$key][1] = "files_folder/".$values["ID"].".jpg"; ----------This is your line

$files_move[$key][1] = "fotos/" ."newFileName" .".jpg";

}
//$values["FieldName"] = $values["ID"].".jpg"; --------- This is your line

$values["FOTO1"] = "newFileName" .".jpg";
//--------------see the array after the change --------

echo ("----------------files_move after change ---- " ."
");

foreach( $files_move as $key=>$val)

{

echo ("Indice= " .$key ."; Valor= " .$val ."
");

}

//-------------------------------------------------------------
//see the new $values

echo ("----------------values despues del cambio---- " ."
");

foreach($values as $field=>$value)

$message.= $field." : ".$value."
";

echo($message);
//------------------------------------------------------------------------------------
return true;
// return true if you like to proceed with adding new record

// return false otherwise
} // function BeforeAdd
//****


**

//****

**
R E S U L T S****

  1. The Record is update
  2. The URL in the propierties "over the field" is ok (Address URL
    A
    Aleix author 1/18/2009

    Hello Jane;
    Your code works! At the end I undertand the code.
    I see that "fileFielName" is the name of my fiel in my table where I store the file with "file" at begining.

    And that "tmp_name" is ok, and I should not modify.

    And the $files_move and $_FILES are 2 dimension variable

    And $_FILES is a superglobal variable.
    Thanks! Jane