This topic is locked
[SOLVED]

 rename

2/16/2010 12:28:53 PM
PHPRunner General questions
G
garethp authorDevClub member

Hi
Following some guidance from Jane I am trying to rename a file on upload with various extension types.
My image field is "document" and my folder on the server is "documents". The ID I am trying to use is "grn"
I am using the followoing code in the before record updated...



global $files_move;

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

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

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

$files_move[$key][1] = "documents/grn".$oldvalues["grn"].".".$ext;

}

$values["document"] = "grn".$oldvalues["grn"].".".$ext;


The rename works fine except the extension is missing from both the document uploaded and renamed document field in the dataabse.
Can you help? ANy is gratefully received as always.

J
Jane 2/17/2010

Hi,
to debug code print all values on the page.

If it doesn't help publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

S
stealthwifi 2/17/2010

garethp use the below rather than CheckImageExtension:

$ext = substr(strrchr($values["field"], '.'), 1);


So your code will look like this:

global $files_move;

$ext = substr(strrchr($values["document"], '.'), 1);

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

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

$files_move[$key][1] = "documents/grn".$oldvalues["grn"].".".$ext;

}

$values["document"] = "grn".$oldvalues["grn"].".".$ext;


P.S I tried the CheckImageType and it only echoes blank no matter what, for whatever reason it's not picking up the values, but substr works great it detects that last . and gets your extension from that

G
garethp authorDevClub member 2/22/2010

Mr Steath
Yuu are a superstar - thanks so much for this. I have only just noticed your solution.
Thanks for taking the time to help - I hae wanted to do this for ages.
Gareth