Welcome Guest, Not a member yet? Register   Sign In
Image Upload Problem
#1

[eluser]JimmyJ[/eluser]
Hey, wonering if anyone can give me a hand with this problem.

I'm trying to upload an image, but keep getting an error where $_FILES['userfile'] is not found.

My form looks like this:

Code:
<form id="form2" name="form2" method="post" action="/admin/pages/addgallery">
<fieldset>
  <legend>Add a new image here</legend>
        <label for="imageName">Image Name</label>
         &lt;input type="text" name="imageTitle" id="imageName" /&gt;
        
         <label for="imageDesc">Image Description</label>
         &lt;input type="text" name="imageDesc" id="imageDesc" /&gt;      
        
        <label for="userfile">Image file</label>
        &lt;input name="userfile" type="file" id="browsefile" /&gt;
      
        &lt;input name="pageID" type="hidden" value="&lt;?php echo $id; ?&gt;" /&gt;
     &lt;input type="hidden" name="post_max_size" value="999999999999"&gt;
     &lt;input type="hidden" name="MAX_FILE_SIZE" value="999999999999"&gt;
       <p> &lt;input type="submit" name="addImage" id="button" value="Upload new image" /&gt;</p>
  </fieldset>
  &lt;/form&gt;

And my upload code looks like this:

Code:
&lt;?php

//echo $_SERVER['DOCUMENT_ROOT'];
print_r($_POST);

    mysql_query("INSERT INTO gallery (pageID, imageTitle, imageDesc) VALUES ('$_POST[pageID]', '$_POST[imageTitle]', '$_POST[imageDesc]')");    
    $imageid = mysql_insert_id();
    
    
    $folder = $_SERVER['DOCUMENT_ROOT'] . 'userFiles/gallery/large/';
    $thumbFolder = $_SERVER['DOCUMENT_ROOT'] . 'userFiles/gallery/thumbs/';
    
        if(!empty($_FILES['userfile'])){ echo '<p style="color:green">file detection successful</p>'; }
        else { echo '<p style="color:red">file failed to upload</p>'; }

    move_uploaded_file($_FILES['userfile']['tmp_name'], $folder.$imageid.".jpg");
    
    if(file_exists($folder.$imageid.".jpg"))
    {
    $this->load->library();
    chmod($folder.$imageid.".jpg", 0777);
    

    $this->load->library('image_lib');
    
    //UPLOAD
    $config['upload_path'] = $folder;
    $config['allowed_types'] = 'jpg';
    $config['max_size']    = '5000';
    $config['max_width']  = '1280';
    $config['max_height']  = '1024';
    $this->load->library('upload', $config);
    
    // RESIZE
    $config[] = 'GD2';
    $config['source_image'] = $folder.$imageid.".jpg";
    $config['maintain_ratio'] = FALSE;
    $config['width'] = 490;
    $config['height'] = 234;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    
    // THUMB
    $config[] = 'GD2';
    $config['source_image'] = $folder.$imageid.".jpg";
    $config['new_image'] = $thumbFolder.$imageid.".jpg";
    $config['maintain_ratio'] = TRUE;
    $config['height'] = 118;
    $config['width'] = 247;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    chmod($folder.$imageid."jpg", 0777);
    
    //CROP THUMB
    $config[] = 'GD2';
    $config['source_image'] = $thumbFolder.$imageid.".jpg";
    $config['x_axis'] = 109;
    $config['y_axis'] = 11;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->crop();
}

die("<p>End</p>");
header("location: /admin/pages/modify/$_POST[pageID]");
?&gt;

I'vve tried it on 2 different servers, checked my php.ini max size, plus put in the hidden fields but it still won't find userfile. It find's the post data ok, so i'm confused!

Anyone have any ideas? Sad
#2

[eluser]Rubiz'[/eluser]
U forgot in the form tag to use enctype
#3

[eluser]charlie spider[/eluser]
ya you would have to use:

&lt;form enctype="multipart/form-data" id="form2" name="form2" action="/admin/pages/addgallery" method="POST"&gt;




Theme © iAndrew 2016 - Forum software by © MyBB