Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用codeigniter在数据库中插入图像高度和图像宽度_Php_Mysql_Codeigniter - Fatal编程技术网

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

Php 无法使用codeigniter在数据库中插入图像高度和图像宽度,php,mysql,codeigniter,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

这是我的控制器代码:

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_高度和img_宽度时,我面临一个问题。它将变为空。

请在图像仍在您的域中时尝试获取图像大小:

摘录:

} 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];

在插入之前,您能否验证您是否获得了图像的高度和宽度?回波图像高度:$image\u高度图像宽度:$image\u宽度;在$result=$this->post\u m->insert\u image之前。我不认为getimagesize可以跨域工作;看起来像