上传 &PHP - 上传取消&页面刷新问题 [英] uploadify & PHP - upload cancel & page refresh issue

查看:40
本文介绍了上传 &PHP - 上传取消&页面刷新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我现有的编程中集成了uploadify 模块,现在一切正常.

I have integrated uploadify module in my existing programming and things work fine right now.

现在,我想做两件事.

1 - 当我在文件上传过程中单击取消按钮时,文件上传过程立即取消,文件不会上传到服务器,但文件名存储在数据库中.那么如何防止脚本在我取消上传时不将数据存储在数据库中呢?请帮忙解决这个问题.

1 - When I click cancel button during file uploading, file upload process is cancelled immediately and file does not upload on server but file name is stored in database. So how to prevent script so it doesn't store data in database when I cancel the uploading? Please help on this.

2 - 文件上传过程完成后是否可以刷新整个网页?也请帮忙解决这个问题.

2 - Is is possible to refresh entire web page after file uploading process is completed? Please help on this too.

非常感谢,克拉

推荐答案

试试这个

$targetFolder = $UPLOAD_PATH; // Relative to the root
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $targetFolder;
$targetFileName = $int_pkid.".".$targetFileExt;;
$targetFile = rtrim($targetPath,'/') . '/' . $targetFileName;

// Validate the file type
$fileTypes = array('pdf','doc','docx'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
    move_uploaded_file($tempFile,$targetFile);
    echo '1';

            //Will Enter this Block only when the upload is success
            //This should fix one of you
            $str_query_insert="INSERT INTO  tr_file_data (pkid,title,filename)";
            $str_query_insert.=" VALUES(".$int_pkid.",'".${str_title}."','".${targetFileName}."')";
            ExecuteQuery($str_query_insert);

            //To Reload, there are no straight legal ways, but can do with a twist
            //Method 1:
            Header('Location: '.$_SERVER['PHP_SELF']);
            Exit(); //optional
            //Method 2:
            echo '<script>parent.window.location.reload(true);</script>';




} else {
    echo 'Invalid file type.';
}
}


// To apply directly to uploadify
$(function() {
    $("#file_upload").uploadify({
        'swf'              : '/uploadify/uploadify.swf',
        'uploader'         : '/uploadify/uploadify.php',
        'onUploadComplete' : function(file) {
            alert('The file ' + file.name + ' finished proce`enter code here`ssing.');

                //Will Enter this Block only when the upload is success
                //This should fix one of you
                $str_query_insert="INSERT INTO  tr_file_data (pkid,title,filename)";
                $str_query_insert.=" VALUES(".$int_pkid.",'".${str_title}."','".${targetFileName}."')";
                ExecuteQuery($str_query_insert);

                //To Reload, there are no straight legal ways, but can do with a twist
                //Method 1:
                Header('Location: '.$_SERVER['PHP_SELF']);
                Exit(); //optional
                //Method 2:
                echo '<script>parent.window.location.reload(true);</script>';

        }
    });
});

这篇关于上传 &amp;PHP - 上传取消&amp;页面刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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