php Gravity表单获取上传文件路径

yk9xbfzb  于 2023-02-03  发布在  PHP
关注(0)|答案(1)|浏览(111)

我有一个重力形式,上传一个文件到条目。我需要得到上传路径后提交。这里是我现有的代码:

add_action( 'gform_pre_submission_13', 'pre_submission_handler' );
function pre_submission_handler( $form ) {
         //get uploaded file url path ( http:// )
}

一些文档会很有帮助

8iwquhpp

8iwquhpp1#

提交后如何获取文件上传路径:

您使用的是错误的钩子gform_pre_submission,您需要使用gform_after_submission
在代码中,不应将操作添加到gform_pre_submission_13(其中13是表单的ID),而应使用gform_after_submission_13
有关详细信息,请参阅此链接:https://docs.gravityforms.com/gform_after_submission/

我的示例代码用于获取提交后的上载路径(其中表单ID为1,上载字段ID为2):

function md_gform_after_submission_1( $entry, $form ) {
 
  $upload_path = GFFormsModel::get_upload_path( $entry[ 'form_id' ] );
  $upload_url = GFFormsModel::get_upload_url( $entry[ 'form_id' ] );
 
  $filename = str_replace( $upload_url, $upload_path, $entry[ '2' ] ); // 2 is the ID of the image field
  echo "<p><b>Your File has been stored here: </b> $filename</p>";
  
}
add_action( 'gform_after_submission_1', 'md_gform_after_submission_1', 10, 2 );

相关问题