Welcome Guest, Not a member yet? Register   Sign In
Am I using libraries/models correctly? This code doesn't work.
#1

[eluser]dallen33[/eluser]
This is in my controller (app.php) (I am loading the Upload.php library already):
Code:
$attach_id = random_string('unique');
                    for ($i = 1; $i <= 10; $i++)
                    {
                        $this->upload->attachments($_FILES['file'.$i]['name'], $_FILES['file'.$i]['tmp_name'], $_FILES['file'.$i]['size'], $_FILES['file'.$i]['type'], $attach_id);
                    }

This is in my library (Upload.php):
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Upload {

    function attachments($fileName, $tmpName, $fileSize, $fileType, $attach_id)
    {
        $uploadDir = '/Applications/MAMP/htdocs/extras/';

        if ($fileSize == 0) { continue; }
        $date = date('F j, Y, g:i:sa');
        $filename_date = date("YmdHis");
        
        mkdir($uploadDir . $attach_id, 0777);
        
        $filePath = $uploadDir . '/' . $attach_id . '/' . $fileName;
        
        $result = move_uploaded_file($tmpName, $filePath);
        
        if(!get_magic_quotes_gpc())
        {
            $fileName  = addslashes($fileName);
            $filePath  = addslashes($filePath);
        }

        $this->booking->attachments($attach_id, $fileType, $fileSize, $filePath);
    }
}

?&gt;

And this is my model (Booking.php):
Code:
&lt;?php
class Booking extends Model {

    function Booking()
    {
        parent::Model();
    }
    
    function attachments($attach_id, $fileType, $fileSize, $filePath)
    {
        $attach_db_data = array(
            'attach_id' => $attach_id ,
            'type' => $fileType ,
            'size' => $fileSize ,
            'path' => $filePath
        );
        $this->db->insert('attachments', $attach_db_data);
    }
}
?&gt;

Basically a user can upload up to 10 files. But when I do this, the browser just sits and times out. Not sure what I'm doing wrong, but this is my first time building a model and a library.
#2

[eluser]Tim Reynolds[/eluser]
Unfortunately I can not spot your error and i currently don't have the time to test your code but a little tip try looking at the CI logs if you have them turned on. I would suggest turning them on for testing look in the user guide for details.

Also if you are running MAMP then you should be able to see the server logs in applications/MAMP/logs even if this does not help this time they are a valuable asset in solving issues.

Tim

PS I assume you are using form_open_multipart()??
#3

[eluser]dallen33[/eluser]
Yeah I'm stumped. However I will try the logging and see if anything shows up.
#4

[eluser]TheFuzzy0ne[/eluser]
How big are the files, and how long does it take to time out?

You may be able to increase the max execution time limit by adding the following to your htaccess file:

Code:
php_value max_execution_time 600




Theme © iAndrew 2016 - Forum software by © MyBB