Rename file

See all posts Reply

Rename file new!
by Mitchel, 14 years, 2 months ago
Hi.

I rename the file to:
$image_name=time().'.'.$_FILES['image']['name'];
$foo->file_new_name_body = 'small_'.$image_name;

Output is: small_1285240138Afb060222jpg.jpg

how to change that? i just want 1 jpg.
Orginal image name: Afb060222.jpg

And how can i put this name to database?Reply
Re: Rename file new!
by colin, 14 years, 2 months ago
I already answered you here.

If you read $_FILES['image']['name'], you have the complete filename, including the extension. You shouldn't use $_FILES anyway.

Please read the documentation. You can for instance use file_src_name to get the originale filename without the extension. Then your code can for instance be:
$foo->file_new_name_body = 'small_'.time().'.'.$foo->file_src_name;

As for the database, as I said in my previous answer, it is outside of the scope of this forum.Reply
Re: Rename file new!
by Mitchel, 14 years, 2 months ago
Sorry, i couldn't find my old topic.

I dont get the answer at my last question.
How can i put the new name in to the database?

I know how to put thing in the database but how do i get the final name from $foo?

Thanks.Reply
Re: Rename file new!
by colin, 14 years, 2 months ago
After calling process(), you can just read one of the following variables:

  • file_dst_path: Destination file path

  • file_dst_name_body: Destination file name body

  • file_dst_name_ext: Destination file extension

  • file_dst_name: Destination file name

  • file_dst_pathname: Destination file complete path and name



Hint: it's all in the docs!Reply
Re: Rename file new!
by Mitchel, 14 years, 2 months ago
Like this?

process();
echo $foo->file_dst_name_body;
Reply
Re: Rename file new!
by colin, 14 years, 2 months ago
Please see the example on the main page

$foo = new Upload($_FILES['form_field']);
if ($foo->uploaded) {
  $foo->file_new_name_body = 'foo';
  $foo->Process('/home/user/files/');
  if ($foo->processed) {
    echo 'file_dst_name_body : '. $foo->file_dst_name_body;
  } else {
    echo 'error : ' . $foo->error;
  }
}
Reply
Re: Rename file new!
by Thomas, 4 years, 7 months ago
Hi, and what if i have this?

$MyObject = new Upload($_FILES['UPLOADFILE']);
if ($MyObject->uploaded) {
$MyObject->file_new_name_body = '{TEST-55888-49651654}';
$MyObject->file_max_size = 31048576;


$MyObject->process($pathupload);
if ($MyObject->processed) {
echo 'OK';
$MyObject->clean();
} else {
echo 'error : ' . $MyObject->error;
}
}

--------------------------------------------------
My problem is that file is saved without {} chars like this:

TEST-55888-49651654.pdf

How to fix this problem ?

Thanks in advanceReply