Güvenli bir klasöre cURL kullanarak dosya gönderme (https://)

0 Cevap php

Sorun güvenli bir klasörde (https://www.mydomain.com/myfolder/) kullanarak cURL içine bir txt dosyası yüklemektir.

Ben bu klasörü bağlamak için ilgili ftp ayrıntılar var. İşte benim kod, ancak düzgün bağlı alma değil ...

Herhangi bir i bu kodun ne yaptığını hata tavsiyelerde lütfen edebilirsiniz. dosyayı yüklerken 7: error_no döndürür

<?
if (isset($_POST['Submit'])) {
    if ($_FILES['upload']['name']!="") 
    {
        $localfile = $_FILES['upload']['tmp_name'];
        $newfile = $_FILES['upload']['name'];
        $ch = curl_init();
        $url = 'ftp://ftp_login:password@ftp.mydomain.com/myfolder/'.$newfile;
        $fp = fopen ($localfile, "r");
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_UPLOAD, 1);
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_FTPASCII, 1);
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $newfile);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        $result = curl_exec($ch);
        echo curl_error($ch);
        echo $error_no = curl_errno($ch);
        curl_close($ch);
        //echo $result;

        if ($error_no == 0) 
        {
            $error = 'File uploaded succesfully.';
        } 
        else 
        {
            $error = 'File upload error.';
        }
    } 
    else 
    {
        $error = 'Please select a file.';
    }
}
?>

0 Cevap