×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

FTP

FTP

(OP)
Is it possible to upload files to a FTP server with PHP ?

RE: FTP

Here is a file that I found. It is comprehensive, and should work:


<?

// QuickUploader
// Nagendra, nagendra@letterbox.com
// 10th Oct 2000       @ Mysore , India
// homepage : http://projects.nagendra.com/quickuploader/
// Released under GNU GENERAL PUBLIC LICENSE http://www.fsf.org
//
// Directions to start cooking
//
// 1. start @ beginning of u r code and define a variable called $path ( ex : $path = "/home/httpd/html/suitesonline.com/"; )
// 2 .include the file upster.php ( ex : include ('upster.php'); )
// 3. print out a variable called $upl wherever u want to place QuickUploader code ( ex : echo "$upl";
//

// Change the Below $path to point to the dir which is the file area
    
// $path = "/var/tmp/";
// $path = "C:/temp/";
$the_path = $path;

if (!$path) {
echo "Path not defined or You are not authorised.";
exit;
}


if ($getty) {

// Code to Handle File Download
// Nagendra, nagendra@letterbox.com
// 20th Sept 2000       @ Mysore , India


$type="Content-type: application/cln";

// get the file & download to visitor

$filename = "$path$getty";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
header("$type");
echo "$contents";
}

// Max File Size to be allowed...change this depending on users upload.. 100k~images/jpgs/gif/docs/etc
$my_max_file_size     = "102400";     # in bytes

function validate_upload($the_file) {
 
global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_types;
    
$start_error = "\n<b>Error:</b>\n<ul>";
    
    if ($the_file == "none") {
    
        $error .= "\n<li>You did not upload anything!</li>";
    
    } else {
    
            list($foo,$width,$bar,$height) = explode("\"",$size[3]);
     
        if ($error) {
            $error = $start_error . $error . "\n</ul>";
            return $error;
        } else {
            return false;
        }
    }
 } # END validate_upload

function list_files() {

global $the_path;
    
    $handle = dir($the_path);
 }
function upload($the_file) {

global $the_path,$the_file_name;
    
    $error = validate_upload($the_file);

    if ($error) {
        form($error);
    } else { # or we can continue

// check if file exists, if then delete the old one before upload

$ffile = $the_path . ' . $the_file;
if ( file_exists("$ffile") ){
unlink ("$ffile");
};
// upload the actuall file here after all checks       
     if (!@copy($the_file, $the_path . "/" . $the_file_name)) {
            form("\n<b>Something barfed, check u r path ");
        }
    }
} # END upload

// HTML upload Form Gen.

$upl = <<<close
<form name="uplink" ENCTYPE="multipart/form-data" action="$PHP_SELF" method="post">
<b><font face="Arial, Helvetica, sans-serif" size="2">Quick Uploader</font></b><Br>
    <INPUT NAME="the_file" TYPE="file" SIZE="5">
    <INPUT TYPE="hidden" name="task" value="upload">
    <input type="Submit" Value="Upload">
</form>
close;

// Delete File

if ($d)
{
unlink ("$path$d");
}

// Determine if file needs to be uploaded/downloaded/deleted

if ($task) {
upload($the_file);
}

if (!$title) {
$title = "Files List:";
}

$upl = $upl."\n<b>$title</b><br>";
$handle = dir($path);
$upl = $upl."<table width=\"28%\" border=\"0\">";
    while ($file = $handle->read()) {
        if (($file != ".") && ($file != "..")) {
$fsize = filesize ($path.$file);
$con = <<<giveup
<tr><td width="13%" height="2"><a href="$PHP_SELF?getty=$file" onMouseOver="drs('Size : $fsize Bytes'); return true;" onMouseOut="nd(); return true;">$file</a>
</td><td width="87%" height="2">
<a href="$PHP_SELF?d=$file">DELETE </a></td></tr>
giveup;
$upl = $upl."$con";
          }
    }
$upl = $upl."</table>";

?>


Hope this helps,

-Vic

vic cherubini
malice365@hotmail.com
www.epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close