function upload($filepath, $extname) { $tracker = fastdfs_tracker_get_connection(); if (!$tracker) { return false; } $storage = fastdfs_tracker_query_storage_store(); if (!$storage) { return false; } $server = fastdfs_connect_server($storage['ip_addr'], $storage['port']); if (!fastdfs_active_test($server)) { return false; } $storage['sock'] = $server['sock']; return fastdfs_storage_upload_by_filename($filepath, $extname, array(), null, $tracker, $storage); }
<?php $group_name = "group1"; $remote_filename = "M00/28/E3/U6Q-CkrMFUgAAAAAAAAIEBucRWc5452.h"; $file_id = $group_name . FDFS_FILE_ID_SEPERATOR . $remote_filename; echo fastdfs_client_version() . "\n"; /* $file_id = $group_name . FDFS_FILE_ID_SEPERATOR . 'M00/00/02/wKjRbExc_qIAAAAAAABtNw6hsnM56585.part2.c'; var_dump(fastdfs_get_file_info1($file_id)); exit(1); */ echo 'fastdfs_tracker_make_all_connections result: ' . fastdfs_tracker_make_all_connections() . "\n"; var_dump(fastdfs_tracker_list_groups()); $tracker = fastdfs_tracker_get_connection(); var_dump($tracker); if (!fastdfs_active_test($tracker)) { error_log("fastdfs_active_test errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info()); exit(1); } $server = fastdfs_connect_server($tracker['ip_addr'], $tracker['port']); var_dump($server); var_dump(fastdfs_disconnect_server($server)); var_dump($server); var_dump(fastdfs_tracker_query_storage_store_list()); $storage = fastdfs_tracker_query_storage_store(); if (!$storage) { error_log("fastdfs_tracker_query_storage_store errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info()); exit(1); } $server = fastdfs_connect_server($storage['ip_addr'], $storage['port']);
/** * 云图片上传 * @return 图片信息 * */ function cloudUpload() { $fileInfo = array(); $isUpload = false; $path = './Uploads/' . date('Y-m-d', time()) . '/'; $path = date('Y-m-d', time()) . '/'; // 获取上传的文件信息,对$_FILES数组信息处理 $files = dealFiles($_FILES); foreach ($files as $key => $file) { //过滤无效的上传 if (!empty($file['name'])) { $temp_name = $file['tmp_name']; $file['ext'] = getExt($file['name']); $tracker = fastdfs_tracker_get_connection(); if (!fastdfs_active_test($tracker)) { error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info()); return false; } $storage = fastdfs_tracker_query_storage_store(); if (!$storage) { error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info()); return false; } $file_info = fastdfs_storage_upload_by_filename($temp_name, $file['ext'], array(), null, $tracker, $storage); $file['group_name'] = $file_info['group_name']; $file['savename'] = $file_info['filename']; $file['savepath'] = $file_info['group_name'] . '/' . $file_info['filename']; //上传成功后保存文件信息,供其它地方调用 unset($file['tmp_name'], $file['error']); $fileInfo[$key] = $file; $isUpload = true; } } if ($isUpload) { //$this->uploadFileInfo = $fileInfo; return $fileInfo; } else { //$this->error = '上传出错!文件不符合上传要求。'; return false; } }