0

そのため、Zend を使用して画像のアップロードを処理しています。このスクリプトはうまく機能しますが、現在のサイズに関係なく、アップロードされている画像のサイズを変更する方法があるかどうか疑問に思っていました. 似たような投稿を 2 つ見たことがありますが、それらのコードはまったく異なるものでした。可能であれば、拡張機能を使用する必要はありませんが、使用する必要がある場合は使用します。何か案は?

if (isset($_POST['upload'])) {
require_once('scripter/lib.php');
//try {
$destination = 'C:\----';
$uploader = new Zend_File_Transfer_Adapter_Http();
$uploader->setDestination($destination);
$filename = $uploader->getFileName(NULL, FALSE);
$uploader->addValidator('Size', FALSE, '10000kB');
$uploader->addValidator('ImageSize', FALSE, array('minheight' => 100, 'minwidth' => 100));
//$pic = $filename;
if (!$uploader->isValid() || $errors) {
    $messages = $uploader->getMessages();
} else {
//$pic = $filename;
$no_spaces = str_replace(' ', '_', $filename, $renamed);
$uploader->addValidator('Extension', FALSE, 'gif, png, jpg');
$recognized = FALSE;
if ($uploader->isValid()) {
    $recognized = TRUE;
} else {
    $mime = $uploader->getMimeType();
    $acceptable = array('jpg' => 'image/jpeg',
                        'png' => 'image/png',
                        'gif' => 'image/gif');
    $key = array_search($mime, $acceptable);
    if (!$key) {
        $messages[] = 'Unrecognized image type';
    } else {
        $no_spaces = "$no_spaces.$key";
        $recognized = TRUE;
        $renamed = TRUE;
    }
}
$uploader->clearValidators();
if ($recognized) {
    $existing = scandir($destination);
    if (in_array($no_spaces, $existing)) {
        $dot = strrpos($no_spaces, '.');
        $base = substr($no_spaces, 0, $dot);
        $extension = substr($no_spaces, $dot);
        $i = 1;
        do {
            $no_spaces = $base . '_' . $i++ . $extension;
        } while (in_array($no_spaces, $existing));
        $renamed = TRUE;
    }
$uploader->addFilter('Rename', array('target' => $no_spaces));
$success = $uploader->receive();
if (!$success) {
$messages = $uploader->getMessages();
} else {
    //$pic = $no_spaces;
    $uploaded = "$filename uploaded successfully";
    $pic = $filename;
    if ($renamed) {
        $pic = "imgs/upld/" . $no_spaces;
        $uploaded .= " and renamed $no_spaces";
        //$pic = $no_spaces;
        //$pic = $uploader->getFileName(NULL, FALSE);

    } else {$pic = "imgs/upld/" . $filename;;}
    $messages[] = "$uploaded";
    //$pic = $no_spaces;

}
4

1 に答える 1