社区
JavaScript
帖子详情
控制台提示一下错误:Response for preflight is invalid (redirect) ,请问怎么解决呢?
qq_41251634
2018-05-16 09:49:47
上传文件时,控制台提示一下错误:Response for preflight is invalid (redirect) ,请问怎么解决呢?
...全文
15061
4
打赏
收藏
控制台提示一下错误:Response for preflight is invalid (redirect) ,请问怎么解决呢?
上传文件时,控制台提示一下错误:Response for preflight is invalid (redirect) ,请问怎么解决呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
qq_41251634
2018-05-17
打赏
举报
回复
<?php /** * upload.php * License: http://www.plupload.com/license * Contributing: http://www.plupload.com/contributing */ // Make sure file is not cached (as it happens for example on iOS devices) header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { exit; // finish preflight CORS requests here } if ( !empty($_REQUEST[ 'debug' ]) ) { $random = rand(0, intval($_REQUEST[ 'debug' ]) ); if ( $random === 0 ) { header("HTTP/1.0 500 Internal Server Error"); exit; } } // header("HTTP/1.0 500 Internal Server Error"); // exit; // 5 minutes execution time @set_time_limit(5 * 60); // Uncomment this one to fake upload time // usleep(5000); // Settings // $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; //$targetDir = 'upload_tmp'; //$uploadDir = 'upload'; $targetDir = 'uploads'.DIRECTORY_SEPARATOR.'file_material_tmp'; $uploadDir = 'uploads'.DIRECTORY_SEPARATOR.'file_material'; $cleanupTargetDir = true; // Remove old files $maxFileAge = 5 * 3600; // Temp file age in seconds // Create target dir if (!file_exists($targetDir)) { @mkdir($targetDir); } // Create target dir if (!file_exists($uploadDir)) { @mkdir($uploadDir); } // Get a file name if (isset($_REQUEST["name"])) { $fileName = $_REQUEST["name"]; } elseif (!empty($_FILES)) { $fileName = $_FILES["file"]["name"]; } else { $fileName = uniqid("file_"); } $oldName = $fileName; $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; //$uploadPath = $uploadDir . DIRECTORY_SEPARATOR . $fileName; // Chunking might be enabled $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 1; // Remove old temp files if ($cleanupTargetDir) { if (!is_dir($targetDir) || !$dir = opendir($targetDir)) { die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); } while (($file = readdir($dir)) !== false) { $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; // If temp file is current file proceed to the next if ($tmpfilePath == "{$filePath}_{$chunk}.part" || $tmpfilePath == "{$filePath}_{$chunk}.parttmp") { continue; } // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\.(part|parttmp)$/', $file) && (@filemtime($tmpfilePath) < time() - $maxFileAge)) { @unlink($tmpfilePath); } } closedir($dir); } // Open temp file if (!$out = @fopen("{$filePath}_{$chunk}.parttmp", "wb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } // Read binary input stream and append it to temp file if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } else { if (!$in = @fopen("php://input", "rb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); rename("{$filePath}_{$chunk}.parttmp", "{$filePath}_{$chunk}.part"); $index = 0; $done = true; for( $index = 0; $index < $chunks; $index++ ) { if ( !file_exists("{$filePath}_{$index}.part") ) { $done = false; break; } } if ( $done ) { $pathInfo = pathinfo($fileName); $hashStr = substr(md5($pathInfo['basename']),8,16); $hashName = time() . $hashStr . '.' .$pathInfo['extension']; $uploadPath = $uploadDir . DIRECTORY_SEPARATOR .$hashName; if (!$out = @fopen($uploadPath, "wb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } if ( flock($out, LOCK_EX) ) { for( $index = 0; $index < $chunks; $index++ ) { if (!$in = @fopen("{$filePath}_{$index}.part", "rb")) { break; } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($in); @unlink("{$filePath}_{$index}.part"); } flock($out, LOCK_UN); } @fclose($out); $response = [ 'success'=>true, 'oldName'=>$oldName, 'filePaht'=>$uploadPath, 'fileSize'=>$data['size'], 'fileSuffixes'=>$pathInfo['extension'], 'file_id'=>$data['id'], ]; die(json_encode($response)); } // Return Success JSON-RPC response die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); 帮我看下这个代码是否有问题?怎么解决?
qq_41251634
2018-05-17
打赏
举报
回复
哪怎么才能让当前页面与上传地址同域呢?
wcwtitxu
2018-05-17
打赏
举报
回复
http://webuploader.duapp.com/webuploader/fileupload.php 这个地址访问不了啊
wcwtitxu
2018-05-16
打赏
举报
回复
跨域了 让你当前页面和上传地址同域 或者 fileupload.php 响应你的 options 请求
php plupload上传失败,php – Laravel Plupload上传到S3的预检反应无效 – CORS
我正在测试在Nginx服务器上的上传到S3的上传.整个项目都是基于Laravel的.问题是当我开始上传时,Chrome的
控制台
说:XMLHttpRequest cannot load http://BUCKET.s3.amazonaws.com/.
Response
for p
ref
light
is
invalid
(
redirect
)我已经尝试使用PHP标头来启用CORS,但仍然出现
错误
.当前上...
部署到linux的war文件访问
提示
错误
,为什么war包在Windows的tomcat正常运行,在linux服务器报errorpage
错误
?...
最近项目完成后打包成war发布到服务器遇到访问应用404问题,用的是tomcat8.5,
错误
信息如下:o.s.b.w.servlet.support.ErrorPageFilter:Cannotforwardtoerrorpageforrequest[/login]asthe
response
hasalreadybeencommitted.Asaresult,...
nginx跨域问题:localhost与127.0.0.1
Spring Boot项目使用Shiro权限管理,存在跨域问题,需要使用nginx反向代理。 配置nginx.conf文件,主要修改如下部分: server { listen 8023; server_name localhost; #charset koi8-r; #access_log lo...
vue.js 的学习
⭐️ ???? ✨ ⚡️ 技术栈 # vue官网http://vuejs.org/# Vuex中文手册http://vuex.vuejs.org # Vue-Router 手册http://router.vuejs.org# 最全Vue资源大全https://github.com/opendigg/awesome-github-vue # vue-devtool 调试vue...
centos7部署posgresql和kong总结
之前在macos系统测试安装psql和kong,但是实际环境中,大部分是部署在linux服务器上。下面记录了在centos7上部署postgresql和kong的总结以及遇到的一些问题的
解决
。 查看centos版本: $ cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 部署版本: kong: v0.13.1 po...
JavaScript
87,993
社区成员
224,694
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章