webuploader php保存数据库,webuploader上传之后,PHP如何获取所有的上传完成的路径?...

//webuploader提供的案例代码:(上传成功,只是想取出路径存到数据库里,单文件上传可以取出,多文件上传,只能取到一个路径)

header ( "Expires: Mon, 26 Jul 2015 02: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;

}

}

@set_time_limit(5 * 60);

$targetDir = 'upload_tmp';

$uploadDir = 'upload';

$cleanupTargetDir = true; // Remove old files

$maxFileAge = 5 * 3600; // Temp file age in seconds

if (!file_exists($targetDir)) {

@mkdir($targetDir);

}

if (!file_exists($uploadDir)) {

@mkdir($uploadDir);

}

if (isset($_REQUEST["name"])) {

$fileName = $_REQUEST["name"];

} elseif (!empty($_FILES)) {

$fileName = $FILES["file"]["name"];

} else {

$fileName = uniqid("file");

}

$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;

$uploadPath = $uploadDir . DIRECTORY_SEPARATOR . $fileName;

$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;

$chunks = isset($REQUEST["chunks"]) ? intval($REQUEST["chunks"]) : 1;

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 ($tmpfilePath == "{$filePath}{$chunk}.part" || $tmpfilePath == "{$filePath}{$chunk}.parttmp") {

continue;

}

if (preg_match('/.(part|parttmp)$/', $file) && (@filemtime($tmpfilePath) < time() - $maxFileAge)) {

@Unlink($tmpfilePath);

}

}

closedir($dir);

}

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 ) {

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);

$arr=array();

$arr[]=$uploadPath;//路径;

// 多文件上传时,数组里也只有一个文件的路径。

//如何取得上传了每个文件的路径?

//求解。。。。

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
webuploader.create()是一个方法,用于创建一个WebUploader实例,该实例可以用来管理文件的上传。在创建实例时,可以传入一些配置参数,用来设置上传的行为和属性。在给定的引用中,可以看到不同的例子展示了不同的配置方式和参数设置。 引用展示了一个用jQuery的方式初始化WebUploader组件的示例。在这个示例中,通过调用initUploader()方法来初始化WebUploader实例,并设置了一些配置参数,比如自动上传上传方式、服务器地址等。 引用展示了一个简单的HTML代码示例,其中包含了一个用于选择文件的按钮和一个用于展示已选择文件名的div。 引用展示了一个更详细的实例化WebUploader的示例,其中包含了更多的配置参数,比如文件选择器、上传服务器地址、分片处理等。 总而言之,webuploader.create()方法用于创建WebUploader实例,并可以通过传入不同的配置参数来定制上传的行为和属性。123 #### 引用[.reference_title] - *1* *2* [WebUploader 上传文件的两种方式(手动上传,自动上传)](https://blog.csdn.net/qq_38974638/article/details/110825971)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [webUploader 的使用实例](https://blog.csdn.net/weixin_41612889/article/details/88541086)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值