Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上传&;PHP-上传取消&;页面刷新问题_Php_Mysql_Uploadify - Fatal编程技术网

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

上传&;PHP-上传取消&;页面刷新问题,php,mysql,uploadify,Php,Mysql,Uploadify,我已经在我现有的编程中集成了uploadify模块,现在一切正常 现在,我想做两件事 1-当我在文件上载过程中单击“取消”按钮时,文件上载过程将立即取消,文件不会上载到服务器上,但文件名存储在数据库中。那个么,当我取消上传时,如何防止脚本在数据库中存储数据呢?请帮忙 2-文件上载过程完成后是否可以刷新整个网页?也请帮忙 非常感谢,, KRA您可以使用OnUploadComplete事件进行上传。上传完成后,您可以保存上传文件的文件名。因此,如果您在这段时间内取消上载,那么它将不会存储在数据库中

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

现在,我想做两件事

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

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

非常感谢,,
KRA

您可以使用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)在上传完成后刷新页面

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

        }
    });
});
$targetFolder=$UPLOAD\u PATH;//相对于根
$verifyToken=md5('unique_salt.$\u POST['timestamp']);
如果(!empty($\u FILES)&&&$\u POST['token']=$verifyToken){
$tempFile=$\u文件['Filedata']['tmp\u名称'];
$targetPath=$targetFolder;
$targetFileName=$int_pkid.“$targetFileExt;”;;
$targetFile=rtrim($targetPath,'/')。$targetFileName;
//验证文件类型
$fileTypes=array('pdf','doc','docx');//文件扩展名
$fileParts=pathinfo($_文件['Filedata']['name']);
if(在数组中($fileParts['extension',$fileTypes)){
移动上传的文件($tempFile,$targetFile);
回声“1”;
//仅当上载成功时才会进入此块
//这会治好你们中的一个
$str_query_insert=“插入tr_文件数据(pkid、标题、文件名)”;
$str_query_insert.=“值(“.$int_pkid.”、“${str_title}.”、“${targetFileName}.”);
ExecuteQuery($str\u query\u insert);
//要重新加载,没有直接的法律途径,但可以做一个扭曲
//方法1:
标题('Location:'.$_SERVER['PHP_SELF']);
Exit();//可选
//方法2:
回显'parent.window.location.reload(true);';
}否则{
回显“无效文件类型”;
}
}
//直接应用于上传
$(函数(){
$(“#文件上传”).uploadify({
“swf”:“/uploadify/uploadify.swf”,
'上传器':'/uploadify/uploadify.php',
“onUploadComplete”:函数(文件){
警报('文件'+file.name+'已完成过程'在此处输入代码');
//仅当上载成功时才会进入此块
//这会治好你们中的一个
$str_query_insert=“插入tr_文件数据(pkid、标题、文件名)”;
$str_query_insert.=“值(“.$int_pkid.”、“${str_title}.”、“${targetFileName}.”);
ExecuteQuery($str\u query\u insert);
//要重新加载,没有直接的法律途径,但可以做一个扭曲
//方法1:
标题('Location:'.$_SERVER['PHP_SELF']);
Exit();//可选
//方法2:
回显'parent.window.location.reload(true);';
}
});
});