Jump to content

FTP issue


mhenderson00

Recommended Posts

Hi all!

I have an upload.php program that uses ftp_put to connect to ftp and upload files.

I am able to connect and upload files.  However, I am able to upload files FROM the directory my php program is running TO
the same server.  I want to ftp a remote file uploaded through my webpage.
When I cature the filename in a form and use that filename as the FROM file, I get an ftp error??'

How do I use FTP to oupload a file from my laptop for example, through my webpage onto my server?'

Please let me know if you need more info

Thanks in advance
Link to comment
Share on other sites

<html>
<title>  </title>
</html>
<?php



function display_info($filename,$video_title,$video_desc,$video_cat)
{
?>
  <p align="center">The file <i><b> <?print basename( $_FILES['uploadedfile']['name']); ?> </b></i> has been uploaded </p><br><br>
<p align="center"><b>Video Title:</b><?print $video_title;?><br><b>Video Description:</b><?print $video_desc;?><br><b>Video Category:</b><? print $video_cat; ?></p>
<?
}

function display_home()
{
      ?>
      <body link="#000000" vlink="#000000" alink="#000000">
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center"><b><font face="Palatino Linotype" size="6">
      <a href="/michelle">HOME</a></font></b></p></body>
      <?
}

function insert_db($filename,$video_title,$video_desc,$video_cat)
{
  $username = "";
  $password = "";
  $hostname = "";
  $dbh = mysql_connect($hostname, $username, $password)
or die("Error Connecting");

  $selected = mysql_select_db("",$dbh)
or die("Error Accessing Database");

  $insert = mysql_query("INSERT INTO video VALUES('$filename','$video_title','$video_desc','$video_cat','mhenderson' )");
  if (!$insert) {
    die("Error Inserting ");
  }
  else { return true; }
}

  $ftp_server = "";
  $ftp_user_name = "";
  $ftp_user_pass = "";
  $video_title = $_POST['video_title'];
  $video_desc = $_POST['video_desc'];
  $video_cat = $_POST['video_category'];
  $filename =  $_FILES['uploadedfile']['name'];
  $target_path = "../../michelle/" . basename( $_FILES['uploadedfile']['name']);
            echo "<br>".$target_path;


  $error_mess ="There was an error uploading the file:".  basename( $_FILES['uploadedfile']['name']).", please try again";
  $success_mess = "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
  $dup_mess ="Filename:".  basename( $_FILES['uploadedfile']['name']);

  if (file_exists($target_path))
      {
      echo "<p align=center><b>File <i>". $target_path ."</i> Already Exists."."</p></b>" ;
      display_home();     
      }
  else {

  if(insert_db($filename,$video_title,$video_desc,$video_cat) == true) {
        $conn_id = ftp_ssl_connect($ftp_server); // login with username and password
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        // check connection
        if ((!$conn_id) || (!$login_result)) {
            echo "FTP connection has failed!";
            print $error_mess;
            display_home();
        }
        else {

          ftp_pasv($conn_id, true);
 
          echo "PASV: On\r\n";
     
            echo "Connected to $ftp_server, for user $ftp_user_name<br>";
            echo $target_path;
            echo " ".$filename." ";

            $getfile = "../".$dir."/temp.txt";
            echo "<br>".$target_path;
            $local_file = "/temp.txt";

            $upload = ftp_put($conn_id, $target_path, '../../michelle/uploads/temp.txt', FTP_BINARY); // upload the file
            if (!$upload) { // check upload stat
                echo "FTP upload has failed!";
                display_home();
            }
            else {
                echo "Uploaded $source_file to $ftp_server as $destination_file";
                display_info($filename,$video_title,$video_desc,$video_cat);
                echo "<p align=center><b>Type: </b>" . $_FILES['uploadedfile']["type"] . "</p>";
                echo "<p align=center><b>Size: </b>" . ($_FILES['uploadedfile']["size"] / 1024) . " Kb</p><br>";
                display_home(); 
            }
            // close the FTP stream
            ftp_close($conn_id);       
        }
  }
  else {
    print "Could not insert into DB";
  }

?>

michelle is the directory my uploader.php is in.  If I try to use the $filename (from the file selected to upload from form) it won't work, I even tried to put the directory in manually (ie C:/temp.txt).  The only time I am successful seems when I upload a file from michelle to somewhere on my same server, since the form is calling a program on my server and I am ftp to my server, it seems I am ftp to myself??? I'm new at this sorry :) how do i create an ftp from my a file on my remote computer, through this program to my websever?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.