David Powers Lesson10 - 'doesn't meet the requirements for an image'
hi,
i have a problem upload image in lesson10. show error message of 'doesn't meet requirements image' image size, width , height meet validation. below upload_images.php
my upload file size 160k width 640 pixels , height 480 pixels. please help. thank you.
upload_images.php
----------------------
<?php
$uploader = new zend_file_transfer_adapter_http();
$uploader->setdestination($destination);
$uploader->setoptions(array('ignorenofile' => true));
$files = $uploader->getfileinfo();
$filenum = 1;
foreach ($files $file => $info) {
$file = "photo{$filenum}";
$caption = $_post["caption{$filenum}"];
if (isset($_post["place_id{$filenum}"])) {
$place_id = $_post["place_id{$filenum}"];
} else {
$place_id = null;
}
$filenum++;
if ($uploader->isuploaded($file)) {
$filename = $uploader->getfilename($file, false);
$uploader->addvalidator('size', false, '500kb');
$uploader->addvalidator('mimetype', false, 'image');
$uploader->addvalidator('imagesize', false, array('minheight' => 50, 'minwidth' => 100));
if (!$uploader->isvalid($file)) {
$errors[$filename] = "$filename doesn't meet requirements image";
} else {
$no_spaces = str_replace(' ', '_', $filename, $renamed);
$uploader->addvalidator('extension', false, 'gif, png, jpg');
$recognized = false;
if ($uploader->isvalid($file)) {
$recognized = true;
} else {
$mime = $uploader->getmimetype($file);
$acceptable = array('jpg' => 'image/jpeg' ,
'png' => 'image/png',
'gif' => 'image/gif');
$key = array_search($mime, $acceptable);
if (!$key) {
$errors[$no_spaces] = "$filename unrecognized image type";
} else {
$no_spaces = "$no_spaces.$key";
$recognized = true;
$renamed = true;
}
}
if ($recognized) {
// names of existing files
$existing = scandir($destination);
// check if name of uploaded file in array
if (in_array($no_spaces, $existing)) {
// position of final period
// use base name , extension
$dot = strrpos($no_spaces, '.');
$base = substr($no_spaces, 0, $dot);
$extension = substr($no_spaces, $dot);
// initialize counter
$i = 1;
// use loop add counter after base name
// check whether new name exists in array
{
$no_spaces = $base . '_' . $i++ . $extension;
} while (in_array($no_spaces, $existing));
// set $renamed true
$renamed = true;
}
$uploader->clearvalidators();
$uploader->addfilter('rename', array('target' => $no_spaces, $info['tmp_name']));
$success = $uploader->receive($file);
if (!$success) {
$errors[$no_spaces] = implode('. ', $uploader->getmessages());
} else {
$uploaded = "$filename uploaded successfully";
if ($renamed) {
$uploaded .= " , renamed $no_spaces";
}
$images[] = array('filename' => $no_spaces,
'caption' => $caption,
'place_id' => $place_id);
$messages[] = $uploaded;
}
}
}
}
}
i able check actual message. error shows the mimetype of file xxx.jpg not detected. xxx filename , have tested in jpg , png format. don't know why validation not accept jpg , png format.
please help.
More discussions in Develop server-side applications in Dreamweaver
adobe
Comments
Post a Comment