PHP导入失败
为了将xls文件从pc上传到MySQL表,我创建了一个PHP上传页面,除了两个问题外,整个过程都很好地满足了需要。 假设进行上传的用户意外关闭了浏览器,或单击了另一个链接;在这种情况下,部分项目上载到MySQL表,其余项目则失败。我如何强制用户等待上传完成,或者创建一个确认框,如果返回false,它将删除已上传的项目 还有另一个问题——是否有一种方法可以在提交后禁用上传按钮,我搜索了谷歌,找到了很多解决方案,但没有一个适用于Chrome浏览器 如果需要,这里是我上传的PHP代码: 这将在提交表单后显示加载程序gif 上传文件 提交后PHP导入失败,php,mysql,forms,upload,submit,Php,Mysql,Forms,Upload,Submit,为了将xls文件从pc上传到MySQL表,我创建了一个PHP上传页面,除了两个问题外,整个过程都很好地满足了需要。 假设进行上传的用户意外关闭了浏览器,或单击了另一个链接;在这种情况下,部分项目上载到MySQL表,其余项目则失败。我如何强制用户等待上传完成,或者创建一个确认框,如果返回false,它将删除已上传的项目 还有另一个问题——是否有一种方法可以在提交后禁用上传按钮,我搜索了谷歌,找到了很多解决方案,但没有一个适用于Chrome浏览器 如果需要,这里是我上传的PHP代码: 这将在提交表单
谢谢各位,任何帮助都将不胜感激 我喜欢你到目前为止所做的一切。非常好的前瞻性思维,能够预测用户的行为 我建议使用jquery进度条 当然,您还需要一个“onwindow close”检测,这样您就可以弹出一个“确认”对话框
$(window).unload(function() {
//do something
}
那么你应该有你的功能
在服务器端保持整洁。只是成功或失败都应该做
除此之外。。。。非常好的工作:
在后端尝试以下操作:
class Uploader
{
$responses = [
'Error : Please Upload Correct Excel File Extension',
'Error : Please Select Excel File to Import !',
'Success: Your file has been processed & uploaded.'
];
function returnResponses($response)
{
return sprintf("<script>alert('%s');
location.replace('import.php');
</script>", $responses[$response]);
}
function checkUpload($file)
{
$filename=$file["tmp_name"];
if(isset($_POST["Import_items"]))
{
if(empty($filename))
{
return $this->returnResponses(1);
}
}
else
{
$allowed = array('csv','xls','xlsx');
$ff = $file['name'];
$ext = pathinfo($ff, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) )
{
return "<center>Extension is Not Excel !</center>" . $this->returnResponses(0);
}
else{
//success & process files
$date = date('Y-m-d');
//process your file
return $this->returnResponses(2);
}
}
}
}
$uploader = new Uploader();
return $uploader->checkUpload($_FILES['file']);
我喜欢你到目前为止所做的一切。非常好的前瞻性思维,能够预测用户的行为 我建议使用jquery进度条 当然,您还需要一个“onwindow close”检测,这样您就可以弹出一个“确认”对话框
$(window).unload(function() {
//do something
}
那么你应该有你的功能
在服务器端保持整洁。只是成功或失败都应该做
除此之外。。。。非常好的工作:
在后端尝试以下操作:
class Uploader
{
$responses = [
'Error : Please Upload Correct Excel File Extension',
'Error : Please Select Excel File to Import !',
'Success: Your file has been processed & uploaded.'
];
function returnResponses($response)
{
return sprintf("<script>alert('%s');
location.replace('import.php');
</script>", $responses[$response]);
}
function checkUpload($file)
{
$filename=$file["tmp_name"];
if(isset($_POST["Import_items"]))
{
if(empty($filename))
{
return $this->returnResponses(1);
}
}
else
{
$allowed = array('csv','xls','xlsx');
$ff = $file['name'];
$ext = pathinfo($ff, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) )
{
return "<center>Extension is Not Excel !</center>" . $this->returnResponses(0);
}
else{
//success & process files
$date = date('Y-m-d');
//process your file
return $this->returnResponses(2);
}
}
}
}
$uploader = new Uploader();
return $uploader->checkUpload($_FILES['file']);
class Uploader
{
$responses = [
'Error : Please Upload Correct Excel File Extension',
'Error : Please Select Excel File to Import !',
'Success: Your file has been processed & uploaded.'
];
function returnResponses($response)
{
return sprintf("<script>alert('%s');
location.replace('import.php');
</script>", $responses[$response]);
}
function checkUpload($file)
{
$filename=$file["tmp_name"];
if(isset($_POST["Import_items"]))
{
if(empty($filename))
{
return $this->returnResponses(1);
}
}
else
{
$allowed = array('csv','xls','xlsx');
$ff = $file['name'];
$ext = pathinfo($ff, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) )
{
return "<center>Extension is Not Excel !</center>" . $this->returnResponses(0);
}
else{
//success & process files
$date = date('Y-m-d');
//process your file
return $this->returnResponses(2);
}
}
}
}
$uploader = new Uploader();
return $uploader->checkUpload($_FILES['file']);