Welcome Guest, Not a member yet? Register   Sign In
why doesn't this upload all the time?
#1

[eluser]vipercat[/eluser]
I've been working at this for awhile now, and it's so frustrating. It would be so awesome if you could look at my code and tell me if i'm doing things wrong, and if I could be doing things a better way (and let me know how I could implement that better way).

It's basically a html form that lets the user upload a file and input some text into a mySQL table.

The text is going into the mySQL table fine, but the file is only sometimes going into its respectable folder. I thought it had to do with the file extensions, but I made sure that they were all defined there, so I guess that can't be it? I don't know maybe? Ahhhh! Please help.

The page is here: http://testing.feministbitch.com/index.php/quiztest/

See here from my controller:
Code:
$config['allowed_types'] = 'doc|docx|pdf|jpg|png';

I have no freaking idea why it's only uploading sometimes and not others.


I autoloaded the following in my autoload.php file:
Code:
$autoload['helper'] = array('url','file','form');
$autoload['libraries'] = array('database');
$autoload['model'] = array('quiz_creator_model','site_model','quiztest_model');

Here's my view quiztest_view.php:
Code:
<!DOCTYPE html>

&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;Create a Quiz&lt;/title&gt;
&lt;style type="text/css" media="screen"&gt;
  label {display: block;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
     <h2>Quiztest</h2>
        &lt;?php echo form_open_multipart('quiztest/createquiz');?&gt;

  <label for="title">Quiz Name:</label>
  &lt;input type="text" name="quiz_name" id="quiz_name" /&gt;&lt;br />
                    &lt;?php echo form_upload('userfile'); ?&gt;
      
<p>
                &lt;?php echo form_submit('upload', 'Upload'); ?&gt;
</p>
&lt;?php echo form_close(); ?&gt;
        
        
        
        &lt;?php echo form_open_multipart('quiztest/do_upload');?&gt;

  <label for="title">Upload file:</label>
                    &lt;?php echo form_upload('userfile'); ?&gt;    
<p>
                &lt;?php echo form_submit('upload', 'Upload'); ?&gt;
</p>
&lt;?php echo form_close(); ?&gt;
        
        
        
        
        

<hr />

<h2>Sample Quizzes</h2>
&lt;?php if(isset($records)) : foreach($records as $row) : ?&gt;

<h2>&lt;?php echo anchor("site/delete/$row->id", $row->title); ?&gt; </h2>
<div>&lt;?php echo $row->content; ?&gt;</div>  

&lt;?php endforeach; ?&gt;

&lt;?php else : ?&gt;
<h2>No records were returned.</h2>
&lt;?php endif; ?&gt;

<hr />

<h2>Delete Quizzes</h2>

<p>
  To delete a quiz, simply click on one of the headings listed above. A delete
  query will automatically run.
</p>

&lt;/body&gt;
&lt;/html&gt;

Here's my controller quiztest.php:

Code:
&lt;?php

class Quiztest extends CI_Controller
{
function index()
{
  $this->load->model('quiztest_model');
                          
                $data = array();
  
  if($query = $this->quiztest_model->get_records())
  {
   $data['records'] = $query;
  }
  
  $this->load->view('quiztest_view', $data);
}
        
        function createquiz()
{
  $data = array(
   'quiz_name' => $this->input->post('quiz_name'),
  );
  
  $this->quiztest_model->add_quizname($data);
  $this->index();
                
//upload study guide
//lag in uploading on hostgator
                $config['upload_path'] = './study-guides/';
  $config['allowed_types'] = 'doc|docx|pdf|jpg|png';
  $config['max_size'] = '60000';
                
                //converts spaces into underscores
                $config['remove_spaces'] = TRUE;
                $config['overwrite'] = FALSE;
                //# will be appended to the filename if another with the same name exists.

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());

   $this->load->view('quiztest_view', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());
                        //$data['file_name'] is the full file name including extension of the file

   $this->load->view('upload-success', $data);
                        $this->load->view('upload-success');
  }
//upload study guide
}
        
        
        
        
function create()
{
  $data = array(
   'title' => $this->input->post('title'),
   'content' => $this->input->post('content')
  );
  
  $this->quiztest_model->add_record($data);
  $this->index();
}

function update()
{
  $data = array(
   'title' => 'My Freshly UPDATED Title',
   'content' => 'Content should go here; it is updated.'
  );
  
  $this->quiztest_model->update_record($data);
}


function delete()
{
  $this->quiztest_model->delete_row();
  $this->index();
}
}


Here's my model quiztest_model.php:
Code:
&lt;?php

class Quiztest_model extends CI_Model {
          
        
  public function __construct()
{
     parent::__construct();
          
        }

function add_quizname($data)
{
  $this->db->insert('quiz_name', $data);
  return;
}
        
function get_records()
{
  $query = $this->db->get('data');
  return $query->result();
}

function add_record($data)
{
  $this->db->insert('data', $data);
  return;
}
        
function update_record($data)
{
  $this->db->where('id', 12);
  $this->db->update('data', $data);
}

function delete_row()
{
  $this->db->where('id', $this->uri->segment(3));
  $this->db->delete('data');
}

}
#2

[eluser]LuckyFella73[/eluser]
Even if you define the ['allowed_types'] you can have
problems due to the mime-types witch can differ depending
what browser you use.

Maybe you can list the types that doesn't work, then other
users here can post their solutions (extending the mimes.php
if necessary). There are many posts about that kind of issues
around these forums - if you want to seach Wink




Theme © iAndrew 2016 - Forum software by © MyBB