uploadify& PHP - 上传取消&页面刷新问题

时间:2012-11-24 06:35:15

标签: php mysql uploadify

我已经在我现有的编程中集成了uploadify模块,现在工作正常。

现在,我想做两件事。

1 - 在文件上传过程中单击取消按钮时,立即取消文件上载过程,文件不在服务器上传,但文件名存储在数据库中。那么如何防止脚本,以便在取消上传时不会将数据存储在数据库中?请帮忙。

2 - 文件上传过程完成后是否可以刷新整个网页?请帮忙。

非常感谢, KRA

2 个答案:

答案 0 :(得分:0)

您可以使用uploadify的OnUploadComplete事件。您可以在上传完成时保存上传文件的文件名。因此,如果您在中间进行上传,那么它将不会存储在数据库中。

$(function() {
    $("#file_upload").uploadify({
        'swf'              : '/uploadify/uploadify.swf',
        'uploader'         : '/uploadify/uploadify.php',
        'onUploadComplete' : function(file) {
            alert('The file ' + file.name + ' finished processing.');
        }
    });
});

另外,对于第二件事,您可以在上面的函数中使用location.reload(true)来在完成上传时刷新页面

答案 1 :(得分:0)

试试这个

$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>';

        }
    });
});