컬 사용할 수 있는 것이 아니라 싶다 데이터를 전송할 수 있는 특정 파일 업로드 매개변수입니다 HTTP POST 양식 이름. 그럼 나가줄까 대해 어떻게 그러는 거야?
HTTP Post 매개변수입니다:
userid = 12345 이는 피레콤망 = 이미지 파일
HTTP 파일 업로드: 파일 위치 = /home/user1/Desktop/test.jpg 이름을 = 이미지 파일 형식 ($ _FILES 해당하는 [& # 39, image& # 39;] php 에서 쪽)
내가 생각 (curl) 의 일부를 다음과 같이 명령을
curl -d "userid=1&filecomment=This is an image file" --data-binary @"/home/user1/Desktop/test.jpg" localhost/uploader.php
나는 이 문제를 가져오는 다음과 같습니다.
Notice: Undefined index: image in /var/www/uploader.php
문제는 _FILES [# 39, & # 39, image&] $ 를 사용하고 있습니다. php 스크립트 파일에 수거.
이에 따라 내 컬 명령의세 조정하십시오 어떻게 합니까?
'-F' 옵션을 사용해야 합니다. '- f / 양식 < name = content>; Multipart 번호여야 HTTP POST 데이터 (H) '
이거 드세요.
curl \
-F "userid=1" \
-F "filecomment=This is an image file" \
-F "image=@/home/user1/Desktop/test.jpg" \
localhost/uploader.php
사용자 id 로 가변적입니다 패스 캐칭 (권장됨):
curl -i -X POST -H "Content-Type: multipart/form-data"
-F "[email protected]" http://mysuperserver/media/1234/upload/
사용자 id 일부로 인기를 양식:
curl -i -X POST -H "Content-Type: multipart/form-data"
-F "[email protected];userid=1234" http://mysuperserver/media/upload/
또는:
curl -i -X POST -H "Content-Type: multipart/form-data"
-F "[email protected]" -F "userid=1234" http://mysuperserver/media/upload/
저는 그동안 판독값 슬라이드에서는 내 솔루션, 그들은 많은 게시물 정말 도움이 됩니다. 마지막으로 나 있는 작은 파일을 컬, PHP 등 일부 코드의 작성했습니까 있는 것 같아 정말 유용합니다.
public function postFile()
{
$file_url = "test.txt"; //here is the file route, in this case is on same directory but you can set URL too like "http://examplewebsite.com/test.txt"
$eol = "\r\n"; //default line-break for mime type
$BOUNDARY = md5(time()); //random boundaryid, is a separator for each param on my post curl function
$BODY=""; //init my curl body
$BODY.= '--'.$BOUNDARY. $eol; //start param header
$BODY .= 'Content-Disposition: form-data; name="sometext"' . $eol . $eol; // last Content with 2 $eol, in this case is only 1 content.
$BODY .= "Some Data" . $eol;//param data in this case is a simple post data and 1 $eol for the end of the data
$BODY.= '--'.$BOUNDARY. $eol; // start 2nd param,
$BODY.= 'Content-Disposition: form-data; name="somefile"; filename="test.txt"'. $eol ; //first Content data for post file, remember you only put 1 when you are going to add more Contents, and 2 on the last, to close the Content Instance
$BODY.= 'Content-Type: application/octet-stream' . $eol; //Same before row
$BODY.= 'Content-Transfer-Encoding: base64' . $eol . $eol; // we put the last Content and 2 $eol,
$BODY.= chunk_split(base64_encode(file_get_contents($file_url))) . $eol; // we write the Base64 File Content and the $eol to finish the data,
$BODY.= '--'.$BOUNDARY .'--' . $eol. $eol; // we close the param and the post width "--" and 2 $eol at the end of our boundary header.
$ch = curl_init(); //init curl
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X_PARAM_TOKEN : 71e2cb8b-42b7-4bf0-b2e8-53fbd2f578f9' //custom header for my api validation you can get it from $_SERVER["HTTP_X_PARAM_TOKEN"] variable
,"Content-Type: multipart/form-data; boundary=".$BOUNDARY) //setting our mime type for make it work on $_FILE variable
);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/1.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'); //setting our user agent
curl_setopt($ch, CURLOPT_URL, "api.endpoint.post"); //setting our api post url
curl_setopt($ch, CURLOPT_COOKIEJAR, $BOUNDARY.'.txt'); //saving cookies just in case we want
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // call return content
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); navigate the endpoint
curl_setopt($ch, CURLOPT_POST, true); //set as post
curl_setopt($ch, CURLOPT_POSTFIELDS, $BODY); // set our $BODY
$response = curl_exec($ch); // start curl navigation
print_r($response); //print response
}
경계해야 할 수 있는 대체하십시오 " api.endpoint.post"; 다음 var 올라왔다. 쉽게 받을 수 있는 기능 '이 있어야 합니다 테스트 스크립트 및 대체하십시오 디버그입니다 포스트피레 ()' 의 마지막 행.
print_r($response); //print response
public function getPostFile()
{
echo "\n\n_SERVER\n";
echo "<pre>";
print_r($_SERVER['HTTP_X_PARAM_TOKEN']);
echo "/<pre>";
echo "_POST\n";
echo "<pre>";
print_r($_POST['sometext']);
echo "/<pre>";
echo "_FILES\n";
echo "<pre>";
print_r($_FILEST['somefile']);
echo "/<pre>";
}
이 솔루션은 물론 이 작품과 함께 노력해야 할 수 있지만 실제로 더 잘 이해하기 위해 mime multipart / 데이터를 이용하여 도움됐네 경계 및 php 와 컬 라이브러리란 작동합니다.
바이너리 파일 업로드, csv 파일 형식을 사용하여 업로드입니다 아래와 같은 경우
curl -X POST \
'http://localhost:8080/workers' \
-H 'authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyIsInR5cGUiOiJhY2Nlc3MifQ.eyJ1c2VySWQiOjEsImFjY291bnRJZCI6MSwiaWF0IjoxNTExMzMwMzg5LCJleHAiOjE1MTM5MjIzODksImF1ZCI6Imh0dHBzOi8veW91cmRvbWFpbi5jb20iLCJpc3MiOiJmZWF0aGVycyIsInN1YiI6ImFub255bW91cyJ9.HWk7qJ0uK6SEi8qSeeB6-TGslDlZOTpG51U6kVi8nYc' \
-H 'content-type: application/x-www-form-urlencoded' \
--data-binary '@/home/limitless/Downloads/iRoute Masters - Workers.csv'
대안으로 '컬' 사용할 수 있습니다. [1], [하트피에] # 39 it& CLI 를 같은 왜곡 인간들말이지 도구입니다.
설치 지침: https://github.com/jakubroztocil/httpie # 설치
그럼 실행하십시오:
http POST - f = 장스노 photo@images/avatar.jpg http://localhost:4040/api/users sername
HTTP/1.1 200 OK 주요 헤더도 액세스 제어: X 프론트엔드 캐시 제어: 저장할 수 없습니다. 연결: 연결을 살려둘 컨텐츠 인코딩입니다: gzip 컨텐츠 길이: 89 콘텐트 유형: text/html. 1251년 indows 문자세트 = 날짜: 화, 26일 6월 2018년 11 11 55 gmt Pragma. 캐시가 없습니다. 서버: 아파치 다르다. 동의하십시오 인코딩입니다 X 프론트엔드: front623311
.
[1]: https://github.com/jakubroztocil/httpie # 파일 업로드 양식 [2]: https://github.com/jakubroztocil/httpie # 설치
여기서 문제가 있는 것으로 드러나 저로하여금진실의 박스트롤의 기본 사용자 오류- 내가 wasn& # 39, t 는 파일의 경로를 로그인하십시오 등 '@' 경로 / 파일의 이름을 올리는 등 왜곡 내용이 아닌. 이에 따라 '는' 이 아닌 값을 컨텐츠 길이 8 점을 감안하면 제 479 제가 걱정했던것 레니스 테스트 파일을 볼 수 있습니다.
이 때 '컬' 컨텐츠 길이 헤더 파일 및 게시물이 자동으로 계산됩니까 판독합니다.
i '컬 - H ", 콘텐트 유형: application/xml". - 데이터 " @test.xml"; - v - X 게시물로의 https://< /<, uri / 'url>;
. <. 컨텐츠 길이: 479 .
여기 글을 다른 새내기 지원하기 위해 향후.