2012-01-20 3 views
0

파일을 업로드하려고 할 때마다 "formpost data failed"응답이 말라서 나타납니다. 웹상의 다른 게시물에서 파일 경로가 틀렸다고 생각하지만 heroku에 대한 절대 경로를 얻지 못하고 있습니다.heroku php 앱에 말림이있는 파일을 업로드하지 못했습니다.

내가 할 때 dirname(__FILE__) 내가 얻을 수있는 것은 바로 될 수없는 /app/www/일까요? heroku 앱에서 절대 파일 경로를 얻으려면 어떻게해야합니까? 이 줄 수 있습니다 나는 문제의 근본 원인을 의심

$ch = curl_init('https://url.com/'.$url); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $result = curl_exec($ch); 
    if(curl_errno($ch)) 
    { 
     return 'Curl error: ' . curl_error($ch); 
    } 
    curl_close ($ch); 
    return $result; 

답변

4

:

이는 이미지 경로에 대한 내 전체 라인은 포스트 데이터

"@".dirname(__FILE__).'/images/wallimages/'.random_pic() 

을 내 컬 설정에 포함되어야하는 것입니다 매뉴얼에서 :

PHP 5.2.0부터 @ 접두사를 사용하여 파일을이 옵션에 전달하는 경우 값이 배열이어야합니다. 어떤 경우

,이 코드를 시도하고 그것이 작동하지 않는 경우, 내가 그렇게 내가 할 수있는 무엇을 얻을 오류 메시지 (들)을 알려 디버그 : 내가 나 자신을 디버깅 할 수 있었다

$uploadPath = rtrim(dirname(__FILE__),'/').'/images/wallimages/'.random_pic(); 
if (!is_file($uploadPath)) die("The file '$uploadPath' does not exist"); 
if (!is_readable($uploadPath)) die("The file '$uploadPath' is not readable"); 

$postFields = array (
    'nameOfFileControl' => "@$uploadPath", 
    'someOtherFormControl' => 'some value' 
    // Adjust this array to match your post fields. 
    // Ensure you keep the array in this format! 
); 

$ch = curl_init('https://url.com/'.$url); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

$result = curl_exec($ch); 

if(curl_errno($ch)) 
{ 
    return 'Curl error: ' . curl_error($ch); 
} 
curl_close ($ch); 
return $result; 
+0

귀하의 추가 코드와 함께. 정말 고마워요. 정말 고마워요. – Jakob

관련 문제