2

I want to upload file and idno using iFrame concept using PHP. I used this code with my project.

This code alone is working fine. The file is uploading. But when it is in my project, it is not working. It showing

undefined index myfile

(I always test in Firefox browser.)

Even an extra parameter idno is also not sending...

But in the same page HTML5 Drag and Drop is working.

any Help?

Here is my code:

<form method="post" action="Nupload.php" enctype="multipart/form-data" class="manual" id="upload_form" target="upload_target">or
<input type="file" name="myfile" id="myfile" style="display:none" onchange="javascript:getReady();" />
<label for="file">select files from your computer...</label>
<input type="hidden" name="idno" value="2013456" />
<iframe src="Nupload.php" name="upload_target" id="upload_target" style="display:none;">    
</iframe>
</form>

Script:

function getReady()
{
document.getElementById("upload_target").onload = uploadDone();
document.getElementById("upload_form").submit();
}

function uploadDone()
{
var content="";
var iframeId=document.getElementById("upload_target");
if (iframeId.contentDocument) {
content = iframeId.contentDocument.body.innerHTML;
} else if (iframeId.contentWindow) {
content = iframeId.contentWindow.document.body.innerHTML;
} else if (iframeId.document) {
content = iframeId.document.body.innerHTML;
}
alert(content)
}

upload.php

if( isset($_FILES["myfile"]) )
{
    $target = basename($_FILES["myfile"]["name"]);

    if(move_uploaded_file($_FILES["myfile"]["tmp_name"],"./temp/".$target))
    {
        $res = array("success"=>true,"file_name"=>$_FILES["myfile"]["name"],"size"=>$_FILES["myfile"]["size"]);
    }
    else
        $res = array("success"=>false,"desc"=>"no");
    echo json_encode($res);
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.