saludos!!, les comento estoy tratando de hacer un script que permita subir una imagen al servidor, le muesto mis algoritmo y la estructura:
controlador: upload.php
<?php
class Upload extends CI_Controller
{
function index()
{
$this->load->view('index', array('error' => ' ' ));
}
public function subir()
{
$config['upload_path'] = base_url()."./images/";
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if ( !$this->upload->do_upload() )
{
$error = array('error' => 'Seleccione Un Archivo Valido de formato ".gif | .jpg | .png | .jpeg" ');
$this->load->view('index', $error);
}
else
{
$file_data = $this->upload->data();
$data['img'] = base_url().'/uploads/'.$file_data['file_name'];
$this->load->view('succes_img', $data);
}
}
}
?>
vista: index.php
<html>
<head> <title> Formulario de Subida </title> </head>
<body>
<?php
for($i=0; $i<6; $i++)
{ echo "<br />"; }
?>
<center>
<?php echo $error;?>
<?php echo form_open_multipart('http://localhost/pruevas_codeigniter/CodeIgniter_2.1.0/index.php/upload/subir');?>
<input type="file" name="userfile" />
<br /><br />
<input type="submit" name="submit" value="upload" />
</form>
</center>
</body>
</html>
vista de resultado: succes_img.php
<html>
<head> <title> Formulario de Subida </title> </head>
<body>
<?php
for($i=0; $i<6; $i++)
{ echo "<br />"; }
?>
<center>
<img src="<?php echo $img ?>" />
</center>
</body>
</html>
la estructura del codeigniter es la siguiente:
CodeIgniter_2.1.0
> Aplicacion
> images
> Sistema
la carpeta images es donde se guardaran las imagenes subidas,,,,
el problema esta en que no funciona para nada, que estare haciendo mal?