提交成功,但是上传不结合的形式工作 [英] submit success but upload not work at combine form

查看:140
本文介绍了提交成功,但是上传不结合的形式工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图合并提交和上传的一种形式,我有一个问题,在上传但提交的形式,它是没有问题的。

JQuery的+ Ajax的:

  $(#oqcsubmit)。点击(函数(){
    如果($(#OQC)。有效()){
            VAR PARAMS = $(#OQC)序列化()。
                $阿贾克斯({
                    类型:后,
                        网址:doinput.php
                        数据:参数,可以
                        缓存:假的,
                        异步:假的,
                        成功:函数(){
                            $(DT)VAL()。
                                $(。STAT)VAL()。
                                回到这一点;
                                },
                        错误:函数(){
                            警报(数据无法输入。);
                                }
                        });
                 返回false;
                 }
     });

<形式ID =OQCENCTYPE =的multipart / form-data的>
    <输入类型=文本ID =modNAME =mod级=DT/>
    &其中;输入类型=文本的id =无名称=无类=DT/>
    <输入ID =文件名NAME =UploadedFile的类型=文件/>
    <输入类型=提交ID =oqcsubmitVALUE =提交/>
    <输入类型=隐藏名称=行动值=oqcdata/>
< /形式GT;
 

PHP:

  $ = DBC的mysql_connect(_SRV,_ACCID,_PWD)或死亡(_ERROR15:.mysql_error());
$分贝= mysql_select_db(QPL,$ DBC)或死亡(_ERROR17:.mysql_error());

$ target_path =数据/;

$ target_path = $ target_path。基本名($ _ FILES ['UploadedFile的'] ['名称']);
//的print_r($ _ FILES);
        如果(move_uploaded_file($ _ FILES ['UploadedFile的'] ['tmp_name的值'],$ target_path)){
                回声文件。基本名($ _ FILES ['UploadedFile的'] ['名称'])。 已上载;
                }
        其他{
                回声发生错误上传文件,请重试!;
                }

开关(postVar('行动')){
        案oqcdata:
                oqcdata(postVar('mod'),postVar('无'));
                打破;
        }

功能oqcdata($ MOD,$无){

        $模式= mysql_real_escape_string($ MOD);
        $串行= mysql_real_escape_string($无);

//生成查询
  $ SQL =INSERT INTO OQC(型号,序列)VALUES('$模式。,$串行。');
回声$ SQL;
$结果= mysql_query($的SQL)或死亡:(_ERROR26.mysql_error()。)
回声$结果;
则mysql_close($ DBC);
 

如何把上传code正确此页?这样既可以工作。 目录权限:搭配chmod 777的数据


该文件被留在后的形式提交(不发送)。


更新

动开关之前,我得到THI错误上传code后:

  PHP公告:未定义指数:UploadedFile的
 

它意味着形式不发送 UploadedFile的值。检查参数后没有 UploadedFile的在内。为什么会发生?即使该值包含表单中使用 .serialize()

 表单数据:
mod:KD-R321ED
无:177X1000 //哪里是上传文件的价值?
动作:oqcdata
 

解决方案

  PHP公告:未定义指数:UploadedFile的
 

     

这意味着,形式不发送UploadedFile的价值。检查参数后没有包括UploadedFile的。为什么会发生?

您的无法通过香草跨浏览器上传文件的AJAX 的,例如,把jQuery使用。期间,句号,故事的结尾。

如果您的必须的做上传不需要刷新页面时,常用的伎俩是创建一个 IFRAME 的形式提交给它。另一个技巧是使用实验文件API ,公开为HTML5的一部分。这可能是一个的疼痛的自己处理,但它应该工作,如果你想手工做这一切。

我的强烈推荐的使用第三方文件上传控件这一点。我有幸与 Plupload 的,但有些人也建议的 Uploadify 。他们既可以选择使用Flash或HTML5后台执行上传,这也给用户带来了快乐的进度表。

During trying to combine submit and upload in one form, I have a problem in upload but for submit form it's no problem.

JQuery + Ajax :

$("#oqcsubmit").click(function() {
    if($("#oqc").valid()) {
            var params=$("#oqc").serialize();
                $.ajax({
                    type:"post",
                        url:"doinput.php",
                        data:params,
                        cache :false,
                        async :false,
                        success : function() {
                            $(".dt").val("");
                                $(".stat").val("");
                                return this;
                                },
                        error : function() {
                            alert("Data failed to input.");
                                }
                        });
                 return false;
                 }
     });

<form id="oqc" enctype="multipart/form-data" >
    <input type="text" id="mod" name="mod" class="dt"/>
    <input type="text" id="no" name="no" class="dt"/>
    <input id="filename" name="uploadedfile" type="file" />
    <input type="submit" id="oqcsubmit" value="Submit" />
    <input type="hidden" name="action" value="oqcdata" />
</form>

PHP :

$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
$db=mysql_select_db("QPL",$dbc) or die(_ERROR17.": ".mysql_error());

$target_path = "data/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
//print_r($_FILES);
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
                }
        else{
                echo "There was an error uploading the file, please try again!";
                }

switch(postVar('action')) {
        case 'oqcdata' :
                oqcdata(postVar('mod'),postVar('no'));
                break;
        }

function oqcdata($mod,$no) {

        $Model          = mysql_real_escape_string($mod);
        $Serial         = mysql_real_escape_string($no);

//build query
  $sql = "INSERT INTO OQC (Model, Serial) VALUES ('".$Model."','".$Serial."')";
echo $sql;
$result=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
echo $result;
mysql_close($dbc);

how to put the upload code correctly in this page? so both could working. directory permission :chmod 777 data


the file is left behind in the form after submit (not send) .


UPDATE

After move the upload code before switch I got thi error:

PHP Notice:  Undefined index: uploadedfile

it's mean that the form not send the uploadedfile value. After check the parameter there are no uploadedfile included. why it happens? even this value is included inside the form and using .serialize().

form data :
mod:KD-R321ED
no:177X1000          // where is the uploaded file value?
action:oqcdata

解决方案

PHP Notice:  Undefined index: uploadedfile

it's mean that the form not send the uploadedfile value. After check the parameter there are no uploadedfile included. why it happens?

You can not upload files over vanilla cross-browser ajax, such as that which jQuery uses. Period, full stop, end of story.

If you must do the upload without a page refresh, the common trick is to create an iframe and submit the form to it. Another trick is to use the experimental File API, exposed as part of HTML5. These can be a pain to handle yourself, but it should work well if you want to do it all by hand.

I highly recommend using a third-party file upload widget for this. I've had luck with Plupload, but some people also recommend Uploadify. They can both optionally use a Flash or HTML5 backend to perform the upload, which also gives users a happy little progress meter.

这篇关于提交成功,但是上传不结合的形式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆