Reputation: 255
I have a spent a few weeks with this issue, and have to ask you for help, I'm using Codeigniter 2.0, and load the file_upload
library from autoload.php, but for some reason the files cannot be uploaded, and does not show any error when I do the do_upload
function, here is a little code of a lot that I have (I have like 9 files input, only shown one on this example, for your comfort).
View
<?php
$atributos = array(
"id" => "form_anuncio",
"name" => "form_anuncio"
);
echo form_open_multipart("usuarios/GrabarAnuncio",$atributos);
?>
<div class="form-group">
<label for="logotipo">Logotipo
<input type="file" name="logotipo" id="logotipo" placeholder="Logotipo" />
</label>
<?php if (($datos_usuario["Logotipo"] != NULL) || ($datos_usuario["Logotipo"] != "")) { ?>
<img src="<?php echo base_url(); ?>images/logos/<?php echo $datos_usuario["idusuario"] . "_" . $datos_usuario["Logotipo"] ?>" alt="Logotipo Usuario" class="img-responsive" />
<?php } ?>
</div>
<div class="form-group">
<input type="submit" name="GuardarAnuncio" id="GuardarAnuncio" value="Guardar Anuncio" />
</div>
<?php echo form_close(); ?>
Controller
public function GrabarAnuncio()
{
$this->load->model('Usuarios_model');
$this->Usuarios_model->Grabar_anuncio();
$this->miperfil();
}
Model (just an extract)
function Grabar_anuncio()
{
/* Lot of code */
$directorio = './images/';
$directorio1 = './images/logos/' . $ID . '/';
if (!is_dir($directorio1)) {
mkdir($directorio1, 0777, true);
}
$directorio2 = './images/fotos/' . $ID . '/';
if (!is_dir($directorio2)) {
mkdir($directorio2, 0777, true);
}
$directorio3 = './images/galerias/' . $ID . '/';
if (!is_dir($directorio3)) {
mkdir($directorio3, 0777, true);
}
if ($_FILES['logotipo']['name'] != "")
{
$config['upload_path'] = $directorio1;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = true;
$config['file_name'] = $_FILES['logotipo']['name'];
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('logotipo'))
{
//Never Enter Here
$serverError = true;
print_r($this->upload->display_errors());
exit();
}
}
/* More code */
}
If you need any more detail you need just ask, I hope you can help me
UPDATE:
This is what i get when i do a var_dump before the upload
array (size=9)
'logotipo' =>
array (size=5)
'name' => string 'grinch1.png' (length=11)
'type' => string 'image/png' (length=9)
'tmp_name' => string 'G:\wamp\tmp\php5E16.tmp' (length=23)
'error' => int 0
'size' => int 58066
'FotosLocalizacion1' =>
array (size=5)
'name' => string 'anviz1.jpg' (length=10)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string 'G:\wamp\tmp\php5E46.tmp' (length=23)
'error' => int 0
'size' => int 219877
'FotosLocalizacion2' =>
array (size=5)
'name' => string 'anviz2.jpg' (length=10)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string 'G:\wamp\tmp\php5E47.tmp' (length=23)
'error' => int 0
'size' => int 172127
'FotosLocalizacion3' =>
array (size=5)
'name' => string 'anviz3.jpg' (length=10)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string 'G:\wamp\tmp\php5E57.tmp' (length=23)
'error' => int 0
'size' => int 136494
'FotosLocalizacion4' =>
array (size=5)
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'galeria1' =>
array (size=5)
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'galeria2' =>
array (size=5)
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'galeria3' =>
array (size=5)
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'galeria4' =>
array (size=5)
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
UPDATE 2
doing this after the if statement (outside of the bracket): die(var_dump($this->upload->data()));
array (size=14)
'file_name' => string 'grinch1.png' (length=11)
'file_type' => string 'image/png' (length=9)
'file_path' => string 'G:/wamp/www/serviciosycomprasx/images/logos/127/' (length=48)
'full_path' => string 'G:/wamp/www/serviciosycomprasx/images/logos/127/grinch1.png' (length=59)
'raw_name' => string 'grinch1' (length=7)
'orig_name' => string 'grinch1.png' (length=11)
'client_name' => string 'grinch1.png' (length=11)
'file_ext' => string '.png' (length=4)
'file_size' => float 56.71
'is_image' => boolean true
'image_width' => int 280
'image_height' => int 280
'image_type' => string 'png' (length=3)
'image_size_str' => string 'width="280" height="280"' (length=24)
Upvotes: 0
Views: 558
Reputation: 376
Change this
function Grabar_anuncio()
{
/* Lot of code */
$directorio = './images/';
$directorio1 = './images/logos/' . $ID . '/';
if (!is_dir($directorio1)) {
mkdir($directorio1, 0777, true);
}
$directorio2 = './images/fotos/' . $ID . '/';
if (!is_dir($directorio2)) {
mkdir($directorio2, 0777, true);
}
$directorio3 = './images/galerias/' . $ID . '/';
if (!is_dir($directorio3)) {
mkdir($directorio3, 0777, true);
}
if ($_FILES['logotipo']['name'] != "")
{
$config['upload_path'] = $directorio1;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = true;
$config['file_name'] = $_FILES['logotipo']['name'];
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('logotipo'))
{
//Never Enter Here
$serverError = true;
print_r($this->upload->display_errors());
exit();
}
}
/* More code */
}
For this
function Grabar_anuncio()
{
/* Lot of code */
$directorio = './images/';
$directorio1 = './images/logos/' . $ID . '/';
if (!is_dir($directorio1)) {
mkdir($directorio1, 0777, true);
}
$directorio2 = './images/fotos/' . $ID . '/';
if (!is_dir($directorio2)) {
mkdir($directorio2, 0777, true);
}
$directorio3 = './images/galerias/' . $ID . '/';
if (!is_dir($directorio3)) {
mkdir($directorio3, 0777, true);
}
if ($_FILES['logotipo']['name'] != "")
{
$config['upload_path'] = $directorio1;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = true;
$config['file_name'] = $_FILES['logotipo']['name'];
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('logotipo'))
{
//Never Enter Here
$serverError = true;
print_r($this->upload->display_errors());
exit();
} else {
$this->upload->data();
}
}
/* More code */
}
Upvotes: 1