CodeIgniter Forums

Full Version: Optional file upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
first question:

Why the file upload in COdeigniter is not optional so that I need to make a trick?

Second one:

In this code below If I select a file it says "You did not select a file to upload." and doesn't upload.
I have title,text,date and file fields in the form.

If I don't select a file there is no problem. Can you help me solve that?

PHP Code:
public function create()

        if (
$this->form_validation->run() === FALSE)
if ($_FILES['dosya']['name'] != ""){
$message="added without file successfully";
$data['title']="Makale Listesi";

private function 
$config['upload_path'] = base_url().'/files/makaleler/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg|pdf|doc|docx|ppt|pptx';
//$config['max_size']    = '100';
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';

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

$data = array('upload' => $this->upload->data());
$message="added successfully with file";
This is a shot in the dark, but did you use form_open_multipart() in your view, or just form_open()?
PHP Code:
<?php if (isset($error))    echo $error;?>

<?php echo form_open_multipart('makale/create');?>

title<input type="text" name="title" /><br /> 
date <input type="text" name="date"  size="20" maxlength="20" /><br />
Text<textarea name="text"> </textarea><br /><br />
File <input type="file" name="dosya" /><br />

<input type="submit" value="send" />




Yes I had.
Try changing $this->upload->do_upload() to $this->upload->do_upload('dosya')
thank you for help. solved now.

I changed the upload path to
$config['upload_path'] = dirname($_SERVER["SCRIPT_FILENAME"]).'/files/makaleler/';