>  기사  >  백엔드 개발  >  PHP가 컬을 사용하여 파일을 업로드하는 이유는 무엇이며 문장을 삭제한 후에는 실행할 수 없습니까?

PHP가 컬을 사용하여 파일을 업로드하는 이유는 무엇이며 문장을 삭제한 후에는 실행할 수 없습니까?

WBOY
WBOY원래의
2016-08-18 09:16:291138검색

<code>   <?php
   function upload_file($url,$filename,$path){
        $data = array('pic'=>'@'.realpath($path).";filename=".$filename);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $return_data = curl_exec($ch);
        curl_close($ch);
        $decode = json_decode($return_data);
        echo $decode->original_pic;      
   }

    if ($_POST) {
        $url = 'https://127.0.0.1/img.php';
        $tmpname = $_FILES['fname']['name'];
        $tmpfile = $_FILES['fname']['tmp_name'];
        upload_file($url,$tmpname,$tmpfile);
        exit;
    }
    echo '<form action="" enctype="multipart/form-data"  method="post">
    <input type="text" name="fname" />
  <input type="file" name="fname" />
  <input type="submit" value="Submit" />
</form>';
?>
</code>

코드는 위와 같은데 을 삭제하고 글을 올릴 수 없는 이유는 무엇인가요?

답글 내용:

<code>   <?php
   function upload_file($url,$filename,$path){
        $data = array('pic'=>'@'.realpath($path).";filename=".$filename);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $return_data = curl_exec($ch);
        curl_close($ch);
        $decode = json_decode($return_data);
        echo $decode->original_pic;      
   }

    if ($_POST) {
        $url = 'https://127.0.0.1/img.php';
        $tmpname = $_FILES['fname']['name'];
        $tmpfile = $_FILES['fname']['tmp_name'];
        upload_file($url,$tmpname,$tmpfile);
        exit;
    }
    echo '<form action="" enctype="multipart/form-data"  method="post">
    <input type="text" name="fname" />
  <input type="file" name="fname" />
  <input type="submit" value="Submit" />
</form>';
?>
</code>

코드는 위와 같은데 을 삭제하고 글을 올릴 수 없는 이유는 무엇인가요?

오류 메시지가 있나요? 게시하고 살펴보세요

. . . 오류가 발생해야 합니다. 실행 시 아무것도 반환되지 않습니까? 그러면 중단하여 어떤 단계가 문제를 일으키는지 확인할 수 있습니다

업로드된 파일 정보는 $_POST가 아닌 $_FILES에 저장되어야 합니다. 그러면 게시물에 미리 $_POST를 입력해야 합니다.
PHP가 컬을 사용하여 파일을 업로드하는 이유는 무엇이며 문장을 삭제한 후에는 실행할 수 없습니까?
테스트 직후 문서 설명이 없습니다. , 제출 이름을 설정할 수 있습니다

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.