Welcome Guest, Not a member yet? Register   Sign In
GD library works on one form but not the other
#1

[eluser]geekindisguise[/eluser]
I used a tutorial that uploaded images resized them. That all works great! And it uses the GD2 library.
Now the problem:
I made another app that will upload images the SAME WAY but also add the rest of the form to a database. It adds to the database just fine. But it says the GD function is not supported. Both pages are on the same server. Why doesn't it work? I used the exact code from the working app to use with my new one. I don't get it.


To view the Working one: http://jacobwilmoth.com/users/CI/

And the NON-Working one: http://jacobwilmoth.com/users/CI/BroJews-CI/

MY MODEL:
Code:
<?php
class Gallery_model extends Model {
    
    var $gallery_path;
    var $gallery_path_url;
    
    function Gallery_model() {
        parent::Model();
        
        $this->gallery_path = realpath(APPPATH . '../images');
        $this->gallery_path_url = base_url().'images/';
    }
    
    function do_upload() {
                
        $config = array(
                        'allowed_types' => 'jpg|jpeg|gif|png',
                        'upload_path' => $this->gallery_path,
                        'max_size' => 10000,
                        );
        
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        
        $image_data = $this->upload->data();
        
        $this->load->library('image_lib');

//[ THUMB IMAGE ]
$img_config_0['image_library'] = 'gd2';
$img_config_0['source_image'] = $image_data['full_path'];
$img_config_0['new_image'] = $this->gallery_path . '/thumbs';
$img_config_0['maintain_ratio'] = TRUE;
$img_config_0['width'] = 154;
$img_config_0['height'] = 154;    
$img_config_0['create_thumb'] = FALSE;
                            
//[ MAIN IMAGE ]
$img_config_1['image_library'] = 'gd2';
$img_config_1['source_image'] = $image_data['full_path'];
$img_config_1['new_image'] = $this->gallery_path . '/enlarged';
$img_config_1['maintain_ratio'] = TRUE;
$img_config_1['width'] = 700;
$img_config_1['height'] = 700;
$img_config_1['create_thumb'] = FALSE;
                    
for($i=0;$i<2;$i++){              eval("\$this->image_lib->initialize(\$img_config_".$i.");");
if($this->image_lib->resize()){
echo " ";                                
}else{
echo "Failed." .$i . $this->image_lib->display_errors();
}
}
        
    }
    
}

The CONTROLLER:
Code:
&lt;?php

class Site extends Controller {
    
    function index()
    {
        $this->load->view('item_adder');
    }
    
    function create() {
        $this->load->model('Gallery_model');
        $this->Gallery_model->do_upload();
        
        $data = array(
            'image_url' => '/BroJews-CI/images/' . $this->input->post('image'),
            'thumb_url' => '/BroJews-CI/images/thumbs/' . $this->input->post('image'),
            'category' => $this->input->post('category'),
            'title' => $this->input->post('title'),
            'description' => $this->input->post('description')
                      );
        
        $this->site_model->add_record($data);
        echo 'Item has been added. Thanks! - Jake';    
    }
}

And the VIEW:
Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Item Adder&lt;/title&gt;
    
    &lt;link rel="stylesheet" type="text/css" href="styles.css"&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id="container">
        <h2>Image Adder</h2>
        
        &lt;?php echo form_open('site/create'); ?&gt;

        <p>
            <label for="image">Image:</label>
            &lt;input type="file" name="image" /&gt;
        </p>

        <p>
            <label for="category">Category:</label>
            <select name="category">
                <option value="turquoise">Turquoise</option>
                <option value="diamonds">Diamonds</option>
                <option value="collectibles">Collectibles</option>
            </select>
        </p>

        <p>
            <label for="title">Title:</label>
            &lt;input type="text" name="title" id="title" /&gt;
        </p>

        <p>
            <label for="description">Description:</label>
            &lt;textarea rows="6" cols="20" name="description" id="description"&gt;&lt;/textarea>
        </p>

        <p>
            &lt;?php     echo form_submit('upload', 'Add this Item'); ?&gt;
        </p>

        &lt;?php echo form_close(); ?&gt;
        
    </div>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]xeroblast[/eluser]
use this in your view:

from: &lt;?php echo form_open('site/create'); ?&gt;

to: &lt;?php echo form_open_multipart('site/create'); ?&gt;
#3

[eluser]geekindisguise[/eluser]
It still says the same thing. The GD function was not supported on this server blah, blah, blah...

But it CAN! I have the same script working on this server. Just doesn't make since.
#4

[eluser]LuckyFella73[/eluser]
Did you set the right permission (writable) for the upload folder
on your second project?

Edit:
if you just press "upload" without selecting an image (first project)
you get this error messages:

Code:
Failed.0

Your server does not support the GD function required to process this type of image.
Failed.1

Your server does not support the GD function required to process this type of image.

Your server does not support the GD function required to process this type of image.

It seems that you get this "not supporting gd function" message even if the error
is not directly related to the library itself


Edit 2:
sorry for spamming your gallery ..
#5

[eluser]xeroblast[/eluser]
i CAREFULLY trace your code and it seems that the problem is in your controller...

you already done the upload that is why it produces the GD function not supported bcoz the image doesnt exist anymore...

you have to do it this way if you want the original, the big resize, and the thumbnail...

first: transfer the $_FILES['image'] to a variable like $original then upload it...
second: again, make another copy of $_FILES['image'] to another variable for the resize like $resize then upload it...
third and last: make another copy of $_FILES['image'] to another variable for the thumbnail like $thumbnail then upload it and you're done...

you can only use the variable once when you do an upload that is why you have to replicate the variable to be use in your upload and resizing...
#6

[eluser]geekindisguise[/eluser]
[quote author="xeroblast" date="1267621459"]i CAREFULLY trace your code and it seems that the problem is in your controller...

you already done the upload that is why it produces the GD function not supported bcoz the image doesnt exist anymore...

you have to do it this way if you want the original, the big resize, and the thumbnail...

first: transfer the $_FILES['image'] to a variable like $original then upload it...
second: again, make another copy of $_FILES['image'] to another variable for the resize like $resize then upload it...
third and last: make another copy of $_FILES['image'] to another variable for the thumbnail like $thumbnail then upload it and you're done...

you can only use the variable once when you do an upload that is why you have to replicate the variable to be use in your upload and resizing...[/quote]

Are you sure? Because the script for uploading works PERFECTLY elsewhere. But not in this. It is the same script too. And how do I make copies of the $_FILES['image']?
Like this:?
Code:
$original = $_FILES['image'];
$resize = $_FILES['image'];
$thumb = $_FILES['image'];

Yes, I am a newbie at all this. So don't make fun of me if what I said above made NO sense or was completely ridiculous.
#7

[eluser]xeroblast[/eluser]
relax... im not making fun of anyone... and YES... do it like that...

bcoz i already tried doing that before in making my joomla component...

once you use the $_FILES, the variable becomes empty... (try it by using your working uploader, after it has been uploaded, try to var_dump() or print_r() the $_FILES and you dont see any value)...

that is why the upload works but after that it wont...




Theme © iAndrew 2016 - Forum software by © MyBB