带有文件浏览按钮的PHP Curl上载文件

带有文件浏览按钮的PHP Curl上载文件,php,file-upload,curl,Php,File Upload,Curl,我想远程上传我的文件到一个接受上传的服务器 使用curl,但每次不使用“@”符号键入完整文件路径 我可以用浏览按钮选择文件,然后继续上传吗 这是我的代码:: $post = array("file_box"=>"@/path/to/myfile.jpg"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://remote-site"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, tru

我想远程上传我的文件到一个接受上传的服务器 使用curl,但每次不使用“@”符号键入完整文件路径 我可以用浏览按钮选择文件,然后继续上传吗

这是我的代码::

$post = array("file_box"=>"@/path/to/myfile.jpg");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://remote-site");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$output = curl_exec($ch);
curl_close($ch);

return $output;
只需通过浏览按钮将“@/path/更改为/myfile.jpg”,该按钮将其值传递给php变量

我想更改这个[[$post=array(“file_-box”=>“@/path/to/myfile.jpg”);]]

做那样的事

[[$post=array(“文件\u框”=>“@”。$variable\u包含来自\u browse\u按钮的\u文件\u路径);]]

防止将文件直接从客户端上传到远程服务器的临时路径中的中间服务器(承载此脚本)

有什么解决办法吗


谢谢大家的帮助。

中有几个问题可以解决

这里是一些链接

谷歌的搜索策略也是如此

但是,由于您要求从前端上传浏览按钮,这里是完整的设置以及导师链接

您可以在这里学习教程,它包含前端和php代码

    $request_url = ‘http://www.example.com/test.php’;
    $post_params['name'] = urlencode(’Test User’);
    $post_params['file'] = ‘@’.'demo/testfile.txt’;
    $post_params['submit'] = urlencode(’submit’);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $request_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
    $result = curl_exec($ch);
    curl_close($ch);
下面是php代码

    $request_url = ‘http://www.example.com/test.php’;
    $post_params['name'] = urlencode(’Test User’);
    $post_params['file'] = ‘@’.'demo/testfile.txt’;
    $post_params['submit'] = urlencode(’submit’);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $request_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
    $result = curl_exec($ch);
    curl_close($ch);
下面是html代码

<form method=”post” action=”test.php” enctype=”multipart/form-data”>
    <input type=”text” name=”name” value=”Test User” />
    <input type=”file” name=”file” />
    <input type=”submit” name=”submit” value=”submit” />
</form>


谢谢aravind.udayashankara,但我不想使用$post_params['file']='@'。'demo/testfile.txt';我想这样使用$post_params['file']=$variable_holding_filePath_from_browse按钮@Mas让我试一试,但您对@any ways有什么问题?我将尽快更新此答案只是为了获得文件类型输入的完整文件路径,以便将文件上载到远程filehoster,而无需先将其上载到我的服务器