Set file name

See all posts Reply

Set file name new!
by jean, 16 years, 4 months ago
Hello,

Iam using your class for multiple files upload.
I want to set the file name in the same that i submit my form.
I have a table (variable+php).

I dont want to use the file name but a name that i have creat before in php.

Can i do that thanksReply
Re: Set file name new!
by colin, 16 years, 4 months ago
You can use the following parameter:
$handle->file_new_name_body = 'new name';

So for instance, you can do:
$handle->file_new_name_body = $_POST['my_field'];
But be careful to escape the field first, otherwise it is a big security risk!Reply
Re: Set file name new!
by jean, 16 years, 4 months ago
hello,

For example i create ma form this way :
$form='
'; $filName="MyName"; for ($i=1;$i<10;$i++) { $newfilName=$filName.i; $form.=''; } $form='
'; print($form);

I want for example have :
for Table=5
5 files uploaded, named :
MyName1, MyName2, MyName3, MyName4, MyName5

How can I set the extension file to let where lick she is in in the original file?

Thanks
Happy New YearReply
Re: Set file name new!
by colin, 16 years, 4 months ago
I am not too sure I understand your question.

For multiple uploads, see the part called "What about multiple uploads?" in the FAQ.Reply
Re: Set file name new!
by jeanmed, 16 years, 2 months ago
I try to set the file name bute it dant works :

here is my code :
$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
  foreach ($l as $i => $v) {
    if (!array_key_exists($i, $files))
      $files[$i] = array();
    $files[$i][$k] = $v;
  }
}
// now we can loop through $files, and feed each element to the class
foreach ($files as $file) {
  //here i want to set set the name of the files :
  $handle->file_new_name_body = "test";
  //and i want to have for a multiple file upload i want for exemple :
  //test1.pdf
  //test2.pdf ..........
  // we instanciate the class for each element of $file
  $handle = new Upload($file);
  // then we check if the file has been uploaded properly
  // in its *temporary* location in the server (often, it is /tmp)
  if ($handle->uploaded) {
    // now, we start the upload 'process'. That is, to copy the uploaded file
    // from its temporary location to the wanted location
    $handle->Process("/home/lclprint/fichiers/");
    //print($handle->file_dst_pathname);
    // we check if everything went OK
    if ($handle->processed) {
      // everything was fine !
      $content.='Vos fichiers ont été correctement transmis.';
      //echo ' file uploaded with success';
    } else {
      // one error occured
      $content.='Vos fichiers n\'ont pas été transmis.';
      //  echo ' file not uploaded to the wanted location';
    }
  } else {
    // if we're here, the upload file failed for some reasons
    // i.e. the server didn't receive the file
  } elseif(isset($_POST['upFichier'])) {
    $handle = new Upload($_FILES['my_field']);
    if ($handle->uploaded) {

    // yes, the file is on the server
    // now, we start the upload 'process'. That is, to copy the uploaded file
    // from its temporary location to the wanted location
    // It could be something like $handle->Process('/home/www/my_uploads/');
    $handle->Process("/home/lclprint/fichiers/");
    // we check if everything went OK
    if ($handle->processed) {
      // everything was fine !
      $content='Votre fichier à été correctement transféré.';
    }
  }
}

ByeReply
Re: Set file name new!
by colin, 16 years, 2 months ago
Replace this line
$handle->file_new_name_body = "test";

With something like:
$i++;
$handle->file_new_name_body = "test".$i;
$handle->file_auto_rename = false;
Reply