为什么redirect()不允许我完成函数调用?

发布于 2024-12-03 20:23:06 字数 3562 浏览 0 评论 0原文

所以我正在编写一个函数,它允许我将一个 ID 从一个数据库表添加到另一个数据库表以将两者关联起来,但我遇到了一些麻烦,似乎不知道该怎么做。任何帮助将不胜感激。

请原谅我的一些混乱的代码,我一直在尝试很多不同的解决方案,但似乎不起作用。

class photo_modle extends CI_Model {

var $gallery_path;
var $image_name;
var $row;
var $gid; // gallary ID
var $iid; // image ID
function photo_modle() {
ob_start();
    $this->gallery_path = realpath(APPPATH . '../images');
}

function uploadPhoto() {


    $config = array(
        'allowed_types' => 'jpg|jpeg',
        'upload_path' => $this->gallery_path,
    );

    $this->load->library('upload', $config);
    $this->upload->do_upload();
    $image_data = $this->upload->data();

    $this->image_name = $image_data['file_name'];
    $config = array(
        'source_image' => $image_data['full_path'],
        'new_image' => realpath($this->gallery_path . '/thumb/normal/'),
        'width' => 248,
        'height' => 198,
        'maintain_ratio' => false
    );

    $this->load->library('image_lib', $config);
    $this->image_lib->resize();

    $data = array(
        'image_name' => $this->image_name,
        'description' => $this->input->post('description'),
        'name' => $this->input->post('name')

    );



    $str = $this->db->insert_string('images', $data);

    $this->db->query($str);
    $this->iid = $this->db->insert_id();


    $grayscale_path = '/Applications/XAMPP/xamppfiles/htdocs/images/thumb/normal/' . $this->image_name;
    header('Content-type: image/jpeg');
    $img = imagecreatefromjpeg($grayscale_path);
    imagefilter($img, IMG_FILTER_GRAYSCALE);
    imagejpeg($img, '/Applications/XAMPP/xamppfiles/htdocs/images/thumb/rollover/' . $this->image_name, 100);
    imagedestroy($img);
    $ndata = array (
        'image_name' => $this->image_name,
        'description' => $this->input->post('description'),
        'name' => $this->input->post('name'),
        'id' => $this->iid
         );

    $this->session->set_userdata($ndata);


}




function add_new_gallery() {


    $ndata = array(
        'gallery_name' => $this->input->post('gallery_name'),
        'description' => $this->input->post('gallery_description'),
     ); 

     $n_str = $this->db->insert('gallery', $ndata);
    // this is the only place where i can put the redirect without it returning errors
    // but if i do it here it does not pass back the gid variable which i need. 
    // I also should mention that I have a  header('Content-type: image/jpeg'); above all of
    // this, and that is why I have to do a redirect, so that I don't get an error. and that 
    // header code is nessasary, for I am doing some photo manipulation that requires it. 
     redirect('site/uploaded'); 
     $this->db->query($n_str);
     $this->gid = $this->db->insert_id();

     // I was trying to send that info in the session, but even that did not work because of the 
     // redirect
     $sdata = array(
         'gallery_id' => $this->gid
     );

     $this->session->set_userdata($sdata);


}
// this function needs the info that is not getting passed. 
function addId() {
      $sdata = array('gallery_id' => $this->session->userdata('gallery_id'));
     $where = "id = ".$this->session->userdata('image_id'); 
     $str = $this->db->update_string('images', $sdata, $where);

     $this->db->query($str);
}

对于任何可以提供帮助的人,非常感谢您抽出宝贵的时间。任何建议都会很棒!

So i'm writing a function that will allow me to add an ID from one data base table to another to associate the two, but i've run into some trubble and can't seem to figgure out what to do. any help would be much appreaceated.

pleas excuse my some what messy code, i've been trying alot of diffrent solutions that don't seem to be working.

class photo_modle extends CI_Model {

var $gallery_path;
var $image_name;
var $row;
var $gid; // gallary ID
var $iid; // image ID
function photo_modle() {
ob_start();
    $this->gallery_path = realpath(APPPATH . '../images');
}

function uploadPhoto() {


    $config = array(
        'allowed_types' => 'jpg|jpeg',
        'upload_path' => $this->gallery_path,
    );

    $this->load->library('upload', $config);
    $this->upload->do_upload();
    $image_data = $this->upload->data();

    $this->image_name = $image_data['file_name'];
    $config = array(
        'source_image' => $image_data['full_path'],
        'new_image' => realpath($this->gallery_path . '/thumb/normal/'),
        'width' => 248,
        'height' => 198,
        'maintain_ratio' => false
    );

    $this->load->library('image_lib', $config);
    $this->image_lib->resize();

    $data = array(
        'image_name' => $this->image_name,
        'description' => $this->input->post('description'),
        'name' => $this->input->post('name')

    );



    $str = $this->db->insert_string('images', $data);

    $this->db->query($str);
    $this->iid = $this->db->insert_id();


    $grayscale_path = '/Applications/XAMPP/xamppfiles/htdocs/images/thumb/normal/' . $this->image_name;
    header('Content-type: image/jpeg');
    $img = imagecreatefromjpeg($grayscale_path);
    imagefilter($img, IMG_FILTER_GRAYSCALE);
    imagejpeg($img, '/Applications/XAMPP/xamppfiles/htdocs/images/thumb/rollover/' . $this->image_name, 100);
    imagedestroy($img);
    $ndata = array (
        'image_name' => $this->image_name,
        'description' => $this->input->post('description'),
        'name' => $this->input->post('name'),
        'id' => $this->iid
         );

    $this->session->set_userdata($ndata);


}




function add_new_gallery() {


    $ndata = array(
        'gallery_name' => $this->input->post('gallery_name'),
        'description' => $this->input->post('gallery_description'),
     ); 

     $n_str = $this->db->insert('gallery', $ndata);
    // this is the only place where i can put the redirect without it returning errors
    // but if i do it here it does not pass back the gid variable which i need. 
    // I also should mention that I have a  header('Content-type: image/jpeg'); above all of
    // this, and that is why I have to do a redirect, so that I don't get an error. and that 
    // header code is nessasary, for I am doing some photo manipulation that requires it. 
     redirect('site/uploaded'); 
     $this->db->query($n_str);
     $this->gid = $this->db->insert_id();

     // I was trying to send that info in the session, but even that did not work because of the 
     // redirect
     $sdata = array(
         'gallery_id' => $this->gid
     );

     $this->session->set_userdata($sdata);


}
// this function needs the info that is not getting passed. 
function addId() {
      $sdata = array('gallery_id' => $this->session->userdata('gallery_id'));
     $where = "id = ".$this->session->userdata('image_id'); 
     $str = $this->db->update_string('images', $sdata, $where);

     $this->db->query($str);
}

to any one that can help thank you sooooooo much for your time. any suggestions would be great!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

变身佩奇 2024-12-10 20:23:06

如果您只是操作图像并将结果保存到文件中,则不需要发送 Content-type: image/jpeg 标头。

当您将图像发送到浏览器时才需要。

您可能对 imagejpeg 的工作原理感到困惑,因为它具有双重行为。 imagejpg 可以:

  • 如果不向浏览器传递$filename,则将图像直接输出到浏览器。当然,您需要警告浏览器需要图像数据,此时您向其发送内容类型标头。

  • 将图像保存到文件(如果您指定了 $filename)。

在您的情况下,您确实向其传递了 $filename ,以便将图像保存到磁盘。但您还发送了 Content-type: image/jpeg,因此您的浏览器期望接收图像数据,但这种情况从未发生,然后它“无法显示,因为它包含错误”。

You don't need to send a Content-type: image/jpeg header if you are just manipulating an image, and saving results to a file.

It's only necessary when you are sending an image to the browser.

You may got confused on how imagejpeg works, as it has a dual behaviour. imagejpg can:

  • Output an image directly to your browser, if you dont pass it a $filename. Of course you need to warn the browser to expect image data, that's when you send it a content type header.

  • Save the image to a file, if you do give it a $filename.

In your case, you do pass it a $filename so the image is saved to disk. But you're also sending a Content-type: image/jpeg so your browser is expecting to receive image data, which never happens, then it "cannot be displayed because it contains errors".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文