从jquery模式弹出窗口上传图像

时间:2011-02-23 08:21:06

标签: jquery upload


我想上传一个图像与jquery模式弹出窗口中显示的其他字段。 我在这里看到了一些答案,我们可以使用iframe从jquery模态对话框上传图像,但是我不能理解清楚..有人可以告诉我该怎么做吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

查看jQuery Form Plugin插件。它可以整齐地处理文件上传。

答案 1 :(得分:1)

我认为Gidon的推荐是好的(+1)另一种选择是uploadify plugin,只是为了给你选择。

编辑文件上传php

<?php


    $error = "";
    $msg = "";
    $filepath = "";
    $fileElementName = $_REQUEST['field'];  //input name

    if(!empty($_FILES[$fileElementName]['error']))
    {
        switch($_FILES[$fileElementName]['error'])
        {
            case '1':
                $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                break;
            case '2':
                $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                break;
            case '3':
                $error = 'The uploaded file was only partially uploaded';
                break;
            case '4':
                $error = 'No file was uploaded.';
                break;

            case '6':
                $error = 'Missing a temporary folder';
                break;
            case '7':
                $error = 'Failed to write file to disk';
                break;
            case '8':
                $error = 'File upload stopped by extension';
                break;
            case '999':
            default:
                $error = 'No error code avaiable';
        }
    }
    elseif(empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none')
    {
        $error = 'No file was uploaded..';
    }
    else 
    {
            $uploaddir = '../../images/content/';
            $uploadname = substr(basename($_FILES[$fileElementName]['name']), -4);
            $uploadfile = $uploaddir . $uploadname;

            if( move_uploaded_file($_FILES[$fileElementName]['tmp_name'], $uploadfile )) 
            {
                // Save image information to db or whatever you want to do here
                $addon_message = "File (" . $uploadfile . ") moved successfully.";
            } else {
                $addon_message = "File failed to copy.";
            }
            /* ----- */
            $msg .= " File Name: " . $_FILES[$fileElementName]['name'] . ", ";
            $msg .= " File Size: " . @filesize($_FILES[$fileElementName]['tmp_name']);
            $msg .= $addon_message;
            $filepath = substr($uploadfile, 3);
            //for security reason, we force to remove all uploaded file
            @unlink($_FILES[$fileElementName]);     
    }       
    echo "{";
    echo                "error: '" . $error . "',\n";
    echo                "msg: '" . $msg . "',\n";
    echo                "filepath: '" . $filepath . "'\n";
    echo "}";
?>