no llego a entender donde esta el problema... o mejor dicho porque me devuelve NULL
cuando hago $metadatase = serialize("$metadata); $metadata es NULL
y el problema deberia ser que foto_thumbnail() me devuelve NULL
Gracias de antemano...
Código PHP:
$metadata = upload_foto($_FILES['foto']['size'], $new_foto, $nome_foto, $part_new_foto);
$querymeta = mysql_query("INSERT INTO wp_4_postmeta (post_id, meta_key, meta_value)
VALUES('". $id_post_foto['ID'] ."', '_wp_attachment_metadata', '$metadata')");
if(!$querymeta) die('error querymeta serialize: ' . mysql_error());
upload_foto (function.php):
Código PHP:
function upload_foto($file_size = null,$temp_foto = null, $nome_foto, $part_new_foto){
$size_bytes = "5242880"; //5MB
if ($file_size > $size_bytes){ die("The file is too large"); }
if ($file_size == "0"){ die("The file can't have 0Kb"); }
$misure = array(
'small-square' => array(
'width' => 50,
'height' => 50,
//'mime-type' => 'image/jpeg',
),
'mini-ec' => Array (
'width' => 135,
'height' => 80,
//'mime-type' => 'image/jpeg',
),
'thumbnail' => Array (
'width' => 150,
'height' => 150,
//'mime-type' => 'image/jpeg',
),
'gallery-links' => array(
'width' => 186,
'height' => 186,
//'mime-type' => 'image/jpeg',
),
'half-landscape' => array(
'width' => 290,
'height' => 166,
//'mime-type' => 'image/jpeg',
),
'medium' => Array (
'width' => 300,
'height' => 169,
//'mime-type' => 'image/jpeg',
),
'blog-one' => array(
'width' => 300,
'height' => 300,
//'mime-type' => 'image/jpeg',
),
'blog-three' => array(
'width' => 620,
'height' => 220,
//'mime-type' => 'image/jpeg',
),
'blog-full-width' => array(
'width' => 620,
'height' => 310,
//'mime-type' => 'image/jpeg',
),
'featured-image' => array(
'width' => 620,
'height' => 350,
//'mime-type' => 'image/jpeg',
),
'featured' => array(
'width' => 700,
'height' => 426,
//'mime-type' => 'image/jpeg',
),
);
$metadata = foto_thumbnail($misure,$temp_foto, $nome_foto, $part_new_foto);
$metadatase = serialize($metadata);
return $metadatase;
}
foto_thumbnail (function.php):
Código PHP:
function foto_thumbnail($misure,$temp_foto, $nome_foto, $part_new_foto){
$image = imagecreatefromjpeg($temp_foto);
$lar = imagesx($image);
$alt = imagesy($image);
$metadata['width'] = $lar;
$metadata['height'] = $alt;
$metadata['file'] = date('Y').'/'.date('m').'/'.$nome_foto.'jpg';
foreach($misure as $m=>$k){
$thumb = imagecreatetruecolor($k['width'],$k['height']);
imagecopyresampled($thumb,$image,0,0,0,0,$k['width'],$k['height'],$lar,$alt);
imagejpeg($thumb, $part_new_foto.$nome_foto.'-'.$k['width'].'x'.$k['height'].'.jpg',90);
$metadata['size'][$k]['file'] = $nome_foto.'-'.$k['width'].'x'.$k['height'].'.jpg';
$metadata['size'][$k]['width'] = $k['width'];
$metadata['size'][$k]['height'] = $k['height'];
$metadata['size'][$k]['mime-type'] = 'image/jpeg';
}
$metadata['image_meta']['aperture'] = 0;
$metadata['image_meta']['credit'] = '';
$metadata['image_meta']['camera'] = '';
$metadata['image_meta']['caption'] = '';
$metadata['image_meta']['created_timestamp'] = 0;
$metadata['image_meta']['copyright'] = '';
$metadata['image_meta']['focal_length'] = 0;
$metadata['image_meta']['iso'] = 0;
$metadata['image_meta']['shutter_speed'] = 0;
$metadata['image_meta']['title'] = '';
return $metadata;
}