无法使用codeigniter在数据库中插入图像高度和图像宽度

时间:2018-03-05 06:44:28

标签: php mysql codeigniter

这是我的控制器代码:

if ($files != '0') {
    //echo "1";
    if (isset($is_anonymous)) {
        $is_anonymous = $is_anonymous;
    } else {
        $is_anonymous = "0";
    }
    $file_ary = $this->Jayesh($_FILES['files']);
    $post_Id = $this->post_m->add_new_post($is_anonymous, $college_id, $writepost, $post, $article, $askq, $user_id, curr_date(), $v_id, $art_title, $art_image, $art_domain, $art_url, $article);
    foreach ($file_ary as $file) {
        $srt = explode('.', $file['name']);
        $ext = $this->getExtension($file['name']);
        $fiel_name = uniqid() . date("YmdHis") . "." . $ext;
        $mime = $file['type'];
        if (strstr($mime, "video/") || strstr($mime, "application/")) {
            $filetype = "video";
            $sourcePath = $file['tmp_name'];
            $targetPath = "images/medical_college_images/video/" . $fiel_name;
            //move_uploaded_file($sourcePath, $targetPath);
            $s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
        } else if (strstr($mime, "image/")) {
            $filetype = "image";
            $sourcePath = $file['tmp_name'];
            $targetPath = "images/medical_college_images/image/" . $fiel_name;
            //move_uploaded_file($sourcePath, $targetPath);
            $s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
        } else if (strstr($mime, "audio/")) {
            $filetype = "audio";
        }

        if (isset($_POST['user_id'])) {
            $user_id = $_POST['user_id'];
            if (!empty($user_id)) {
                $user = $this->post_m->check_user_exist_timeline($user_id);
                if (!empty($user)) {
                    if ($filetype == 'video') {
                        $image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/video/" . $fiel_name);
                        $image_width = '0';
                        $image_height = '0';
                        $video_width = '300';
                        $video_height = '160';
                    }

                    if ($filetype == 'image') {
                        //echo "https://d2c8oti4is0ms3.cloudfront.net/images/healthwall_media/image/".$fiel_name;
                        $image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/image/" . $fiel_name);
                        $image_width = $image_info[0];
                        $image_height = $image_info[1];

                        $video_width = '300';
                        $video_height = '160';
                    }
                    //exit();
                    /* $last_user_id = $this->post_m->insert_image_post_into_media($fiel_name, $filetype,curr_date());
                      if (!empty($last_user_id))
                      { */


                    $result = $this->post_m->insert_image_post_into_post_media($post_Id, curr_date(), $image_width, $image_height, $video_height, $video_width, $fiel_name, $filetype);
                    //}
                }
            }
        }
    }

型号代码:

public function insert_image_post_into_post_media($post_Id, $cdate, $image_width, $image_height, $video_height, $video_width, $fiel_name, $filetype) {
    $sql = "INSERT INTO college_post_media( `post_id`,`type`, `source`, `img_height`, `img_width`, `video_height`, `video_width`, `created_at`, `updated_at`, `deleted_at`)
         VALUES ('$post_Id','$filetype','$fiel_name','$image_height', '$image_width','$video_height',  '$video_width', '$cdate','$cdate','$cdate')";

    return $result = $this->db->query($sql);
}

img_heightimg_width插入表格时,我遇到了问题。它是空的。

1 个答案:

答案 0 :(得分:0)

尝试获取仍在您网域中的图片尺寸:

摘录:

} else if (strstr($mime, "image/")) {
    $filetype = "image";
    $sourcePath = $file['tmp_name'];

    list($image_width, $image_height) = getimagesize($file['tmp_name']);

    $targetPath = "images/medical_college_images/image/" . $fiel_name;
    //move_uploaded_file($sourcePath, $targetPath);
    $s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
}

假设$file['tmp_name']是完全限定的路径。

然后你可以删除:

                $image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/image/" . $fiel_name);
                $image_width = $image_info[0];
                $image_height = $image_info[1];
相关问题