This topic is locked

rename file on upload with unknown extenion

7/17/2009 3:28:42 PM
PHPRunner General questions
G
garethp authorDevClub member

Hi
I have seen some posts on this but not sure how to implement the complete code. I need to rename an uploaded file to have the same of the id of the record it is being uploaded to. I have seen the following code...

global $files_move;

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

{if($val[0]==$_FILES["file_image_url"]["tmp_name"])

$files_move[$key][1] = "photo/PH".$values["employee_number"].".jpg";

}

$values["image_url"] = "PH".$values["employee_number"].".jpg";


This is ok for jpg's but what if you have numerous extensions. I have seen you can check the extension with...

$ext = CheckImageExtension($_FILES["file_FieldName"]["name"]);


However, I am unsure how to properly combine these. Can you please help?
Many thanks
Gareth

J
Jane 7/20/2009

Gareth,
here is a sample:

global $files_move;

$ext = CheckImageExtension($_FILES["file_image_url"]["name"]);

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

{if($val[0]==$_FILES["file_image_url"]["tmp_name"])

$files_move[$key][1] = "photo/PH".$values["employee_number"].".".$ext;

}

$values["image_url"] = "PH".$values["employee_number"].".".$ext;