Welcome Guest, Not a member yet? Register   Sign In
Uploading 2 files
#1

[eluser]peekk[/eluser]
Hi!
I have problem when i want to upload more than 1 file on my server, i have two fields for files in my form (userfile, userfile_watermark) my uploading code is:

Code:
if($_FILES['userfile_watermark']['size']>0){
$new_filename_watermark = $this->file_name($_FILES['userfile_watermark']['name']);
$config['upload_path'] = './sounds/watermark';
$config['allowed_types'] = 'mp3|wav';
$config['file_name'] = $new_filename_watermark;
$this->load->library('upload', $config);
$this->upload->do_upload();
}

  
if($_FILES['userfile']['size']>0){
$new_filename = $this->file_name($_FILES['userfile']['name']);
$config['upload_path'] = './sounds';
$config['allowed_types'] = 'mp3|wav';
$config['file_name'] = $new_filename;
$this->load->library('upload', $config);
$this->upload->do_upload();
}

and both files are uploaded to /sounds/watermark/ and their names are $new_filename_watermark (one should be just: $new_filename). I see that i want to load my library two times and probably that's wrong. How can i reload this or something like that?

Cheers!
#2

[eluser]aquary[/eluser]
Code:
$this->load->library('upload');
if($_FILES['userfile_watermark']['size']>0){
$new_filename_watermark = $this->file_name($_FILES['userfile_watermark']['name']);
$config['upload_path'] = './sounds/watermark';
$config['allowed_types'] = 'mp3|wav';
$config['file_name'] = $new_filename_watermark;
$this->upload->initialize($config);
$this->upload->do_upload();
$this->upload->clear();
}
  
if($_FILES['userfile']['size']>0){
$new_filename = $this->file_name($_FILES['userfile']['name']);
$config['upload_path'] = './sounds';
$config['allowed_types'] = 'mp3|wav';
$config['file_name'] = $new_filename;
$this->upload->initialize($config);
$this->upload->do_upload();
$this->upload->clear();
}
#3

[eluser]peekk[/eluser]
It's still uploading file only from first upload initialization... Thx anyway!
Any other ideas?
How to clear the library initialization data nad initialize it again with another data?
#4

[eluser]peekk[/eluser]
I was trying several other methods, but i just can't figure it out. Can someone tell me how to initialize this library again with new data?
#5

[eluser]PhilTem[/eluser]
I never used the upload-class, but I think it's similar to the HTML-table class in terms of clearing. Try to do the clear before initializing the library.

And maybe use
Code:
$this->upload->data();

rather than
Code:
$this->upload->do_upload();

for debugging.
#6

[eluser]aquary[/eluser]
Are you sure the script actually goes into the second? Try echo something inside the second IF, then you could var_dump($_FILES) also.
#7

[eluser]LuckyFella73[/eluser]
Did you try this to get details about the failure:
Code:
<?php
$this->load->library('upload');
if($_FILES['userfile_watermark']['size']>0)
{
$new_filename_watermark = $this->file_name($_FILES['userfile_watermark']['name']);
$config['upload_path'] = './sounds/watermark';
$config['allowed_types'] = 'mp3|wav';
$config['file_name'] = $new_filename_watermark;
$this->upload->initialize($config);
#$this->upload->do_upload();
if ( ! $this->upload->do_upload())
{
  echo $this->upload->display_errors();
  exit();
}

$this->upload->clear();
}
?>

An other thing (just thinking about folder permissions) you said:
Quote:both files are uploaded to /sounds/watermark/

But your script has 2 different upload folders defined. Maybe one
the folders has not the right permissions? (That's why I would
implement the output of errors while trying to upload like suggested).
#8

[eluser]gRoberts[/eluser]
Code:
<?

$this->load->library('upload');
foreach($_FILES as $Key => $File)
{
  if($File['size'] > 0)
  {
   $filename = $this->file_name($File['name']);
   $config['upload_path'] = './sounds';
   $config['allowed_types'] = 'mp3|wav';
   $config['file_name'] = $filename;
   $this->upload->clear();
   $this->upload->initialize($config);
   if($this->upload->do_upload($Key))
   {
    // success
   }
   else
   {
    // error
   }
  }
}
?>

You'll find that when calling do_upload without any paramaters, it will be expecting an input file with a name of "userfile".

The above will loop through each of the uploaded files and upload it accordingly (untested, but based on previous experiences, it should work).

HTH




Theme © iAndrew 2016 - Forum software by © MyBB