Zend framework 如何将我的zend脚本图片文件名放入隐藏字段

Zend framework 如何将我的zend脚本图片文件名放入隐藏字段,zend-framework,upload,image,hiddenfield,Zend Framework,Upload,Image,Hiddenfield,好吧,我被难住了。我正在使用Zend脚本来帮助我上传图片。它工作得很好,但我正在尝试将图片名称捕获到表单的隐藏字段中。我想指出的是,名称发生了变化,因此我需要得到最终被放入隐藏字段的名称。以下是Zend脚本: <?php if (isset($_POST['upload'])) { require_once('scripts/library.php'); try { $destination = 'xxxxxxxx'; $uploader = n

好吧,我被难住了。我正在使用Zend脚本来帮助我上传图片。它工作得很好,但我正在尝试将图片名称捕获到表单的隐藏字段中。我想指出的是,名称发生了变化,因此我需要得到最终被放入隐藏字段的名称。以下是Zend脚本:

<?php
if (isset($_POST['upload'])) {
require_once('scripts/library.php');

    try {

        $destination = 'xxxxxxxx';
        $uploader = new Zend_File_Transfer_Adapter_Http();
        $uploader->setDestination($destination);

        $filename = $uploader->getFileName(NULL, FALSE);
        $uploader->addValidator('Size', FALSE, '90kB');
        $uploader->addValidator('ImageSize', FALSE, array('minheight' => 100, 'minwidth' => 100));

        if (!$uploader->isValid()) {
            $messages = $uploader->getMessages();
        } else {

            $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 {

                    $uploaded = "$filename uploaded successfully";
                    $pic = $filename;
                    if ($renamed) {
                        $uploaded .= " and renamed $no_spaces";
                    }
                    $messages[] = "$uploaded";
                }
            }
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}

$pic
变量就是我试图将zend脚本中的文件名复制到的变量。非常感谢您的反馈:)

我不太清楚您希望在这里实现什么目标?您在$filename变量中还没有文件名吗?如果要在用户选择要上载的文件时更新隐藏字段,则在将页面发送到服务器之前,需要使用客户端脚本(javascript)来更新该字段。如果你需要帮助,请告诉我。。。
if (isset($_POST['upload'])) {  } else { $pic = "unknown";}