【发布时间】:2019-10-04 15:46:03
【问题描述】:
我想在本地保存后将图像文件名和路径发送到外部服务器。我的 form.php 文件:
<form action="server.php" method="post" enctype="multipart/form-data">
Upload a File:
<input type="file" name="myfile" id="fileToUpload">
<input type="submit" name="submit" value="Upload File Now" >
</form>
和服务器。 php文件:
<?php
if (isset($_FILES['myimage']['tmp_image'])) {
$path = "uploads/".$_FILES['myimage']['name'];
move_uploaded_file($_FILES['myimage']['tmp_image'], $path);
}
$target_url = "http://endpoint.ext/api/img";
$post = array('avatar'=> $path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
?>
使用此代码,脚本仅成功上传但没有发送到端点,任何人都可以帮助我:(
还有一些调试信息:
Array ( [myfile] => Array ( [name] => detail-rotate.jpg [type] => image/jpeg [tmp_name] => E:\xampp\tmp\phpDCB6.tmp [error] => 0 [size] => 553013 ) ) Array ( [submit] => Upload File Now )
非常感谢
【问题讨论】:
-
我试过了,但没有用。仍然向另一台服务器发送空值
-
这是错误响应:curl_close():提供的资源不是有效的cURL句柄资源
-
嗨@Kevin,尝试了很多方法,但看起来我的 curl 无法获取文件
标签: php html twitter-bootstrap curl