Welcome Guest, Not a member yet? Register   Sign In
Form Data and File Upload
#21

[eluser]wowdezign[/eluser]
Which solution did you try? What exactly is happening in your case?
#22

[eluser]cestaz18[/eluser]
[quote author="wowdezign" date="1264105796"]Which solution did you try? What exactly is happening in your case?[/quote]

uhmm..all the solution u mention in this thread i tried in my form...but it doesnt work on me..the above code i posted is the recent code i have after trying ur solution..please help me..i thought the problem is in my controller function???in the array $fields where i use POST?


in my case ...

i have 6 input text field..and 1 uplading field for image

and my problem is...no value has been saved in my icon field in my database...but all other input text field value has been succesfully saved in the database...


here's my sample form below for you to figure out my problem...
#23

[eluser]BigJobbies[/eluser]
Hey ... How would i work this with multiple file fields?

I have 5 fields, their names are userfile[] ... I cant seem to get your examples to work.

I have tried this:

Code:
if (isset($_FILES['userfile']) && $_FILES['userfile']['error'] != 4){
    echo 'THIS IS NOT FUNNY';
}

and also this

Code:
if($_FILES['userfile']['error'] != 4){
    echo 'WORK DAMNIT';
}

Neither of which works.

Cheers,
#24

[eluser]nizsmo[/eluser]
[quote author="Intervelopment" date="1291745623"]Hey ... How would i work this with multiple file fields?

I have 5 fields, their names are userfile[] ... I cant seem to get your examples to work.

I have tried this:

Code:
if (isset($_FILES['userfile']) && $_FILES['userfile']['error'] != 4){
    echo 'THIS IS NOT FUNNY';
}

and also this

Code:
if($_FILES['userfile']['error'] != 4){
    echo 'WORK DAMNIT';
}

Neither of which works.

Cheers,[/quote]

You will need to go 1 level deeper, as you have an array of "userfile"s:

Code:
if($_FILES[0]['userfile']['error'] != 4){
    echo 'WORK DAMNIT';
}

Obviously you have to do this in a loop, and replace the zero with what is applicable (or use foreach.).
#25

[eluser]Funky Fresh[/eluser]
Hey,

I tried your suggestion .... It didnt work, but i tried something else which worked.

Code:
if($_FILES['userfile']['error'][0] == 4){
}
#26

[eluser]nizsmo[/eluser]
[quote author="Funky Fresh" date="1291794940"]Hey,

I tried your suggestion .... It didnt work, but i tried something else which worked.

Code:
if($_FILES['userfile']['error'][0] == 4){
}
[/quote]

Apologies, I did get the counter around the wrong way, thanks for posting the correct solution.
#27

[eluser]klintjefferson[/eluser]
i also have a problem. The $_FILES is empty when i pass it as a POST value. Here is my code. hope you can help me guys.

this is my FORM
Code:
<form name="frmAudioadd1" id="frmAudioadd1" method="POST" action="<?php echo base_url()?>video/save1" enctype="multipart/form-data">                                                  

<table width="600">
  <tr>
    <td width="20" valign="top"><div class="datalabel" align="left">Title</div></td>
    <td>
     &lt;input type="text" name="video_title1" id="video_title1" value="" size="38"/&gt;
     &lt;input type="hidden" name="source1" id="source1" value="" /&gt;
    </td>
  </tr>    
  <tr>  
    <td width="20"><div class="datalabel" align="left">Video</div></td>        
    <td width="250">
      <div align="left">
         &lt;input type="file" id="video" name="video" &gt;
      </div>
    </td>
  </tr>  
  <tr>
    <td width="20"><div class="datalabel" align="left">Description</div></td>
    <td width="250" height="300">
      <div align="left">
       &lt;textarea name="description1" id="description1" cols="50" rows="15"&gt;&lt;/textarea>    
</div></td>                        
   </tr>  
    <tr>
    <td width="20"><div class="datalabel" align="left">Featured&nbsp;</div></td>
       <td width="250">
        <select name="featured1" id="featured1" class="select">
          <option value="">- please select -</option>
          <option value="1">YES</option>
           <option value="2">NO</option>
      </select>
    </tr>
  <tr>
  <td width="20"><div class="datalabel" align="left">Archive&nbsp;</div></td>
  <td width="250"> <select name="archive_name1" id="archive_name1" class="select">
    <option value="">- please select -</option>    
    &lt;?php
      if($video_archive){                        
      foreach($video_archive as $indexcountry){
     ?&gt;
    <option value="&lt;?php echo $indexcountry["id"]; ?&gt;">
    &lt;?php echo $indexcountry["archive_name"]; ?&gt;</option>
    &lt;?php
        }
         }
     ?&gt;
     </tr>
    <tr>
      <td>&nbsp;</td>
    <td>&lt;input type="button" name="cmdSave1" id="cmdSave1"&gt;/input></td>
                                                </tr>
                                                 </table>
                                           &lt;/form&gt;


This is my function in saving the video.
Code:
function save1()
    {  
        $path = 'uploads/video';  
        $config['upload_path'] = $path;
        $config['allowed_types'] = 'mp4|mpg|m4v';
        $config['max_size']   = '10000000'; //size in kilobytes
     //   $config['max_width'] = '295';
     //   $config['max_height'] = '250';
        
        $this->load->library('upload', $config);
        

        if($_FILES['video']['name']!="" && $_FILES['video']['name']!="")
        {                                      
            $target_path_small = $path .'/'. basename( $_FILES['video']['name']);
            move_uploaded_file($_FILES['video']['tmp_name'], $target_path_small);
        }
    }
#28

[eluser]LuckyFella73[/eluser]
I prefer to let the fileupload be a part of the form_valdation
and use a callback function to upload like this:
Code:
if ( isset($_FILES['userfile']['name']) AND strlen($_FILES['userfile']['name']) > 3 )
{
$this->form_validation->set_rules('userfile', 'Image', 'callback__do_image_upload');
}

Otherwise you need more if statements in case the fileupload failed when
it comes to process the form data in general.
#29

[eluser]klintjefferson[/eluser]
[quote author="LuckyFella73" date="1349430847"]I prefer to let the fileupload be a part of the form_valdation
and use a callback function to upload like this:
Code:
if ( isset($_FILES['userfile']['name']) AND strlen($_FILES['userfile']['name']) > 3 )
{
$this->form_validation->set_rules('userfile', 'Image', 'callback__do_image_upload');
}

Otherwise you need more if statements in case the fileupload failed when
it comes to process the form data in general.[/quote]

thank you for looking up bro. Smile i'll try this one and see if this works.
#30

[eluser]klintjefferson[/eluser]
after days of browsing the internet. ahaha. finally i got the video upload working.
for those who had the same issue as mine. look up the code shown above, my 1st post. I think thats a pretty correct to upload photo and dont forget to:
1st - add the correct mime type for the audio, video, image on the array if it still dont exist. as for mine. i added the:
= 'wmv' => array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'),
= 'flv' => array('video/flv', 'video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
= 'm4v' => 'video/x-m4v',
= 'mp4' => 'video/mp4',
since the are mostly the videos that i will be uploading.
2nd - I added:
= AddType video/x-m4v m4v
= AddType audio/x-m4a m4a
= AddType video/mp4 mp4
on the .htaccess
3rd - if you upload videos which is more that 2mb or 5mb. surely CI will provide you an error. The code which really provided me with the success:
= php_value upload_max_filesize 50M
= php_value post_max_size 50M
= php_value max_execution_time 200
= php_value max_input_time 200
i added this also on the .htaccess so that it can upload up to 50mb video.

~ i hope this could help and if their is a problem about my solution. feel free to tell me why. i am just also a novice. Smile




Theme © iAndrew 2016 - Forum software by © MyBB