好的,所以使用phonegap我已经构建了一个从iphone库上传图像的应用程序。它将它发送到php脚本,该脚本解码base64图像并写入文件。我现在的问题是它是一个base64图像,我需要复制它并用代码点火器调整它的大小。就像我说它写文件很好,但无法读取文件来调整大小。
到目前为止,这是我的代码:
if ($_POST['image']) {
// convert the image data from base64
$imgData = base64_decode($_POST['image']);
// set the image paths
$path = './assets/site/images/photo_gallery/';
$file = md5(date('Ymdgisu')) . '.jpg';
$file_path = $path . $file;
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$username = trim($_POST['username']);
$galID = $this->model_mobile->get_user_galID($username);
if($galID){
$galleryID = $galID[0]->galleryid;
write_file($path . $galleryID . '/' . $file, $imgData);
$data = array (
'date_added' => date('o-m-d H:i:s'),
'parentuid' => $galleryID,
'image_url' => $file,
'title' => $title,
'description' => $description,
'gallery_face' => 0,
'active' => 1
);
$config['source_image'] = '/assets/site/images/photo_gallery/' . $galleryID . '/' . $file;
$config['quality'] = '100%';
$config['new_image'] = '/assets/site/images/photo_gallery/' . $galleryID . '/s_' . $file;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'width';
$config['width'] = 200;
$config['height'] = 150;
$this->image_lib->initialize($config);
$this->image_lib->resize();
//$this->db->insert('table', $data);
echo 1;
}else{
echo 0;
}
}else {
echo 0;
}
}
更新:我已经解决了这个问题! 在我的js文件中,我将图像数据发送为base64编码。它已经是。所以只需发送数据,然后像上面的PHP一样解码,工作完美。 希望这有助于某人!