我有簡單的ajax上傳形式使用iframe。我想要的是,加載消息顯示< div id="message"></div>
ajax php上傳文件與上傳百分比
上傳百分比這是我的javascript
function start_Uploading(){
document.getElementById('message').innerHTML = 'Uploading...';
return true;
}
function stopUpload(success)
{
var result = '';
if (success == 1)
document.getElementById('message').innerHTML = 'Success';
else
document.getElementById('message').innerHTML = 'Failed';
}
這是形式
< div id="message"><br/></div>
< form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="start_Uploading();" >
File:< input name="myfile" type="file" size="30" />
< input type="submit" name="submitBtn" value="Upload" />
< br/>< iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
</form>
和服務器端上傳。 php file is
$destination_path = getcwd().DIRECTORY_SEPARATOR;
$result = 0;
$target_path = $destination_path . basename($_FILES['myfile']['name']);
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path))
$result = 1;
sleep(1);
echo "<script language=\"javascript\" type=\"text/javascript\">window.top.window.stopUpload($result);</script>";
它通過顯示js噱頭直到99%給用戶。當上傳完成和PHP返回成功顯示100%。 – zod 2011-05-02 19:06:02