This topic is locked
[SOLVED]

 Changing uploaded file name - not work

3/3/2010 4:34:55 PM
PHPRunner General questions
H
horsey_kim author

I am trying to get this to work from this page; http://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
It suppose to let you rename an upload file.
Here is what I plugged in Add page: Before record added and Edit page: Before record updated events.
--------------------------
global $files_move;
foreach( $files_move as $key=>$val)
{
if($val[0]==$_FILES["file_photo"]["tmp_name"])
$files_move[$key][1] = $values["description"].".jpg";
}
$values["photo"] = $values["description"].".jpg";
--------------------------------------
THIS IS THE RESULTS:
The file name in mysql is correct and changed, but the file uploaded is the old file name! So it does not recognize the file.
I also like to add - I was trying to get it to label the file with the auto assigned record id number generated by mysql, but I get nothing. I think it is because the number to the listing is probably done after the file is uploaded and the record is saved.
So does anyone have a solution on what the correct thing would be to make it work for both changing in mysql database and it save the file uploaded the same new name?
Kim

Sergey Kornilov admin 3/3/2010

keys array is only available in AfterAdd event. In BeforeAdd event record is not created yet which means there is no key.

H
horsey_kim author 3/5/2010



keys array is only available in AfterAdd event. In BeforeAdd event record is not created yet which means there is no key.





I am using 5.2

This is what you say to do in your manual and were I was directed to accomplish the renaming of files uploaded:

To rename upload files based on ID field use the following code in Add page: Before record added and/or Edit page: Before record updated events.

Note: Change the values listed in red to match your specific needs.
global $files_move;
foreach( $files_move as $key=>$val)
{
if($val[0]==$_FILES["file_FieldName"]["tmp_name"])
$files_move[$key][1] = "files_folder/".$values["ID"].".jpg";
}
$values["FieldName"] = $values["ID"].".jpg";

In this example FieldName and ID are actual field names, files_folder is the directory where the files will be stored.[/i]


If I do it as per stated in the manual it renames the file in mysql but not file uploaded.
If I do it in the After Add event, it does nothing at all.
I am still trying to accomplish the file renaming with no luck. I am not sure where to go now. Manual seems to be wrong, I guess.

H
horsey_kim author 3/11/2010

YEAH!!!! Thanks Support for helping me with a solution to my problem. Support does it again!
Visit here for what worked for me: http://www.asprunner.com/forums/topic/14012-changing-uploaded-photos-names-very-useful/