大家好,
这是我用来在GF中上传多文件上传的最终代码。该代码已经过测试,并且已经由我的第三方系统验证。
$form_id = $entry[ '1' ];
$upload_path = GFFormsModel::get_upload_path( $form_id );
$upload_url = GFFormsModel::get_upload_url( $form_id );
$arrPaths = str_replace( $upload_url, $upload_path, $entry[ 'x' ] );
$Paths = explode('","', substr($arrPaths, 1, -1));
$t=1;
foreach ($Paths as $key => $path) {
$path = str_replace('"', '', $path);
$path = str_replace('\/', '/', $path);
$path = str_replace('["', '', $path);
$path = str_replace('"]', '', $path);
$Paths[$key] = $path;
$add_client_files_POA = array(
"strURL" => $path,
"nClientId" => $clientId,
"nContactId" => $contactId,
"fileType" => rgar( $entry, 'y' ),
"fileName" => "Proof of Address" . $t
);
if(!empty($add_client_share_three_payload['strURL'])) {
$add_client_response = $client->UploadCtcFileURL($add_client_files_POA);
}
$t=$t+1;
}
非常感谢您对此提供的帮助。所有的评论都把我带到了最后。
感谢安德鲁
我有一个字符串,该字符串从多个文件更新以重力形式在文件数组中输出。我需要将每个文件拆分为自己的变量,以便可以将每个文件上传到外部服务器。字符串输出如下:
"https:\/\/www.xyz.com\/folder\/sub-folder\/example1.jpg","https:\/\/www.xyz.com\/folder\/sub-folder\/example2.jpg","https:\/\/www.xyz.com\/folder\/sub-folder\/example3.jpg","https:\/\/www.xyz.com\/folder\/sub-folder\/example4.jpg"
我将需要分离这些文件中的每个文件,然后运行一个函数以分别上传每个文件,因为API不允许一次上传多个文件。
我认为我需要运行 foreach 命令,但是我需要删除“” ,,并替换 / 和 / 。这可能吗?
我的SOAP上传如下。
$form_id = $entry[ '1' ];
$upload_path = GFFormsModel::get_upload_path( $form_id );
$upload_url = GFFormsModel::get_upload_url( $form_id );
$POI = str_replace( $upload_url, $upload_path, $entry[ 'y' ] );
$add_client_files_POI = array(
"strURL" => $POI,
"nClientId" => $clientId,
"nContactId" => $contactId,
"fileType" => rgar( $entry, 'x'),
"fileName" => rgar( $entry, 'x')
);
$add_client_response = $client->UploadCtcFileURL($add_client_files_POI);
我正在使用此功能上传单个文件,并且效果很好。
预先感谢...
答案 0 :(得分:0)
尝试这样的事情:
//get paths with " removed
$arrPaths = explode('","', substr($paths, 1, -1));
foreach ($arrPaths as $path) {
//change / characters
$path = str_replace('\/', '/', $path);
}
编辑:
//get paths with " removed
$arrPaths = explode('","', substr($paths, 1, -1));
foreach ($arrPaths as $path) {
//change \/ to / characters
$path = str_replace('\/', '/', $path);
$add_client_files_POI = array(
"strURL" => $path,
"nClientId" => $clientId,
"nContactId" => $contactId,
"fileType" => rgar( $entry, 'x'),
"fileName" => rgar( $entry, 'x')
);
$add_client_response = $client->UploadCtcFileURL($add_client_files_POI);
}