gpt4 book ai didi

php - 将上传的文件发布到另一个 PHP 页面?

转载 作者:可可西里 更新时间:2023-11-01 17:15:58 25 4
gpt4 key购买 nike

这是我的问题。我有一个不太“用户友好”的工单跟踪系统,但我希望我的用户在不让他们看到的情况下向系统提交“工单”。

我只使用自定义 HTTP 表单并发布到工单跟踪系统。一个问题是“成功/完成”页面容易让人感到困惑。所以我想......好吧,因为我无法更改票证系统以使用不同的“成功”页面。我将只处理与 CURL 的 HTTP Post 交换并报告自定义成功或问题页面。这是一些抽象代码。

文件:tickethelper.php

<?php
extract($_POST);
$url = 'TICKETSYSTEMURL';
$fields = array(
'fullname'=>urlencode($fullname),
/*many more fields*/
);

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_MAXREDIRS, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec($ch);
curl_close($ch);
if((strlen(strstr($contents,'Your ticket has been submitted')))>0){
header("Location: http://THANKYOU");
}
else{
header("Location: http://OOPS");
}

?>

但是,我意识到我丢失了文件上传。我见过的大多数 CURL 示例都与将本地文件上传到远程 HTTP POST 页面有关。

我如何处理从我的用户 HTTP 表单接收文件、在“tickethelper”中处理它并将其发布到“TICKETSYSTEMURL”?

-以色列

最佳答案

好吧,我不能说这是我自己完成的,但是根据有关 CURL 和文件处理的 PHP 文档 (PHP.net)

CURLOPT_INFILE | The file that the transfer should be read from when uploading.

value should be a stream resource (using fopen(), for example) for the following values of the option parameter:

您应该能够在已上传的文件上调用 fopen()(请参阅有关 Handling File Uploads 的文档)我不确定,但您可能需要调用 在调用 fopen()

之前将_uploaded_file() 移动到服务器上的受控目录

例如:

$ch = curl_init();

$file = fopen($_FILES['file-field-name']['tmp_name'], 'r');

// OTHER CURL CONFIGURATION
curl_setopt($ch, CURLOPT_INFILE, $file);

curl_exec($ch);

关于php - 将上传的文件发布到另一个 PHP 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1917260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com