文件上传未将数据发布到iframe

时间:2013-08-03 12:44:42

标签: php forms iframe file-upload

我有一个简单的文件上传表单,该表单发布到iframe,我从iframe中检索值并重定向到另一个页面。

问题是表单没有发布到iframe(我不这么认为)因此没有执行任何php而且null正在返回到javascript。

HTML代码

<form id="upload" name="upload" enctype="multipart/form-data" method="post" action="index.php" target="upload_target">
   <input name="folder" type="hidden" value="<?php echo $folder ?>"  />
   <input name="filename" type="hidden" value="<?php echo $filename ?>"  />
   <input name="uploaded_file" type="file" size="5120" id="uploaded_file" accept="image/jpeg"  />
    <input id="sent" name="sent" type="submit"  value="Upload" />
</form>
<iframe id="upload_target" name="upload_target" style="width:10px; height:10px; display:none"></iframe>

Javascript从iframe获取值

$('form#upload').submit(function(){  

    $('#upload_wrapper').hide();
    $('#loading').show();

    // get the uploaded file name from the iframe
    $('#upload_target').unbind().load( function()
    {                               
      var img = $('#upload_target').contents().find('#filename').html();
      alert(img); //returning null
      $('#loading').hide();

     });
});

页面顶部的PHP上传文件

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$targetFolder = $_POST['folder'] . "/";
$filename2 = $_POST['filename'];

if (!is_dir($targetFolder)) 
{
    mkdir($targetFolder, 0777);
}

    $tempFile = $_FILES['uploaded_file']['tmp_name'];
    $targetPath = dirname(__FILE__) . '/' . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['uploaded_file']['name'];

    $uploadfile = $targetFolder. basename($filename2 .".jpg");
    move_uploaded_file($tempFile,$uploadfile);
    $fileName = $uploadfile;

    echo "<div id='filename'>$fileName</div>";

}

此代码之前一直在运作,所以我不确定为什么它现在停止请帮助。

0 个答案:

没有答案