Forum Sementara Putera.com

Bersama kita perkemaskan forum ini sementara forum asal dalam pemulihan.

Forum putera dah kembali. Masalah sudah berjaya diselesaikan. Sila lawati http://forum.putera.com/tanya


    [Blom Setel] FTP Upload via Web (PHP)

    Share

    yurckk
    Ahli Baharu
    Ahli Baharu

    Number of posts : 227
    Age : 32
    Location : Middle Earth
    Registration date : 17/02/2009

    [Blom Setel] FTP Upload via Web (PHP)

    Post by yurckk on Wed Sep 23, 2009 11:51 am

    Assalamualaikum,

    Ade sesape pnh experience wat bnde ni x? or tau pasal bnde ni, ni aku ade trjmpe source code. Tapi
    aku xbp phm sgt... noob sgt dlm PHP... hehe..

    Code:
      1.
          // FTP access parameters:
      2.
          $host = 'ftp.example.org';
      3.
          $usr = 'example_user';
      4.
          $pwd = 'example_password';
      5.
         
      6.
          // file to upload:
      7.
          $local_file = './example.txt';
      8.
          $ftp_path = '/data/example.txt';
      9.
         
      10.
          // connect to FTP server (port 21)
      11.
          $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
      12.
         
      13.
          // send access parameters
      14.
          ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
      15.
         
      16.
          // turn on passive mode transfers (some servers need this)
      17.
          // ftp_pasv ($conn_id, true);
      18.
         
      19.
          // perform file upload
      20.
          $upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
      21.
         
      22.
          // check upload status:
      23.
          print (!$upload) 'Cannot upload' : 'Upload complete';
      24.
          print "\n";
      25.
         
      26.
          /*
      27.
          ** Chmod the file (just as example)
      28.
          */
      29.
         
      30.
          // If you are using PHP4 then you need to use this code:
      31.
          // (because the "ftp_chmod" command is just available in PHP5+)
      32.
          if (!function_exists('ftp_chmod')) {
      33.
          function ftp_chmod($ftp_stream, $mode, $filename){
      34.
          return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
      35.
          }
      36.
          }
      37.
         
      38.
          // try to chmod the new file to 666 (writeable)
      39.
          if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
      40.
          print $ftp_path . " chmoded successfully to 666\n";
      41.
          } else {
      42.
          print "could not chmod $file\n";
      43.
          }
      44.
         
      45.
          // close the FTP stream
      46.
          ftp_close($conn_id);

    Terima Kasih... and selamat Hari Raya!


    Last edited by yurckk on Wed Sep 23, 2009 2:05 pm; edited 1 time in total

    yurckk
    Ahli Baharu
    Ahli Baharu

    Number of posts : 227
    Age : 32
    Location : Middle Earth
    Registration date : 17/02/2009

    Re: [Blom Setel] FTP Upload via Web (PHP)

    Post by yurckk on Wed Sep 23, 2009 11:54 am

    Yang ni lain plak:

    Code:
    <form action="curlupload.php" method="post" enctype="multipart/form-data">
    <div>
    <label for="upload">Select file</label>
    <input name="upload" type="file" />
    <input type="submit" name="Submit" value="Upload" />
    </div>
    </form>

    Code:
    if (isset($_POST['Submit'])) {
     if (!empty($_FILES['upload']['name'])) {
        $ch = curl_init();
        $localfile = $_FILES['upload']['tmp_name'];
        $fp = fopen($localfile, 'r');
        curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_login:password@ftp.domain.com/'.$_FILES['upload']['name']);
        curl_setopt($ch, CURLOPT_UPLOAD, 1);
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
        curl_exec ($ch);
        $error_no = curl_errno($ch);
        curl_close ($ch);
            if ($error_no == 0) {
               $error = 'File uploaded succesfully.';
            } else {
               $error = 'File upload error.';
            }
     } else {
           $error = 'Please select a file.';
     }
    }

    yurckk
    Ahli Baharu
    Ahli Baharu

    Number of posts : 227
    Age : 32
    Location : Middle Earth
    Registration date : 17/02/2009

    Re: [Blom Setel] FTP Upload via Web (PHP)

    Post by yurckk on Wed Sep 23, 2009 11:58 am

    Kalau boleh, untuk User masukkan ftp.domainname.com, password variable.. bukan static, tapi bergantung pada user..

    Path dgn port sama, IP address yang sama gak (hosting yang sama). Tq. Smile

    yurckk
    Ahli Baharu
    Ahli Baharu

    Number of posts : 227
    Age : 32
    Location : Middle Earth
    Registration date : 17/02/2009

    Re: [Blom Setel] FTP Upload via Web (PHP)

    Post by yurckk on Wed Sep 23, 2009 1:05 pm

    Thanks all, nvm... dah dpt nak buat and dah jadi Smile
    Drpd dlu nak buat, hehe.. lepas post kt sini baru le aku rajin godek2 coding ne..
    Selamat Hari Raya!


    Ehhh... jap2 xsetel lg, yang aku test skrg upload file drpd computer ke hosting. Mcm mn lak kalo nak upload file dr hosting1 ke hosting2.


    HTML
    Code:
    <input type="url" name="userfiles[]"><br>

    PHP
    Code:
    If(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){

    xdpt read url tu..


    contoh:
    UserName: admin
    Password: passwordcontoh
    ftp: ftp.contoh.com
    Read Url: filelain.com/abc.jpg

    Bila Click Submit >

    File abc.jpg akan yang dari filelain.com/abc.jpg tu akan di uploadkan ke contoh.com

    Cmne aa? tq Smile

    xenomorf
    Ahli Baharu
    Ahli Baharu

    Number of posts : 239
    Location : BehinD ThE WaLL
    Registration date : 26/03/2009

    Re: [Blom Setel] FTP Upload via Web (PHP)

    Post by xenomorf on Wed Sep 23, 2009 2:15 pm

    klu ko rajin nk godek2 sgt, ko download net2ftp pya source code. tgok kat dlm tu.

    Sponsored content

    Re: [Blom Setel] FTP Upload via Web (PHP)

    Post by Sponsored content Today at 4:14 pm


      Current date/time is Tue Dec 06, 2016 4:14 pm