使用c_url上传文件到远程主机,文件名不正确

发布于 2024-10-05 12:37:39 字数 646 浏览 0 评论 0原文

使用 c_url 将文件上传到远程主机。这是我的代码。

 <?php

/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/autouvl/public_html/asmallorange/log.txt');

curl_setopt($ch, CURLOPT_URL, 'http://www.test.com/test/receivefile.aspx');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

echo(curl_exec($ch));
?> 

问题:在我的receivefile.aspx中。我得到的文件名是“/home/autouvl/public_html/asmallorange/log.txt”。但我想要它应该是“log.txt”,而不是完整路径。除了文件名不正确外,文件可以成功上传。

我的代码出了什么问题?

谢谢你!

Using c_url upload file to remote host. here is my code.

 <?php

/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/autouvl/public_html/asmallorange/log.txt');

curl_setopt($ch, CURLOPT_URL, 'http://www.test.com/test/receivefile.aspx');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

echo(curl_exec($ch));
?> 

Question: in my receivefile.aspx. I got the file name is "/home/autouvl/public_html/asmallorange/log.txt". but I want It should be "log.txt", not full path. file can be uploaded successfully except incorrect file name.

what's wrong in my code?

thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅人 2024-10-12 12:37:39
$data = array('name' => 'Foo', 'file' => '@/home/autouvl/public_html/asmallorange/log.txt;filename=log.txt');
$data = array('name' => 'Foo', 'file' => '@/home/autouvl/public_html/asmallorange/log.txt;filename=log.txt');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文