Jump to content

uploading files to ftp using php(help)


desithugg

Recommended Posts

[code]
<?php
// get FTP access parameters
$host = "sssasdas";
$user = "admin@tpfrpg.byethost32.com"
$pass = "password"
$destDir = "../pics/";
$workDir = "/usr/pics/temp"; // define this as per local system

// get temporary file name for the uploaded file
$tmpName = basename($_FILES['file']['tmp_name']);

// copy uploaded file into current directory
move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName)
or die("Cannot move uploaded file to working directory");

// open connection
$conn = ftp_connect($host) or die ("Cannot initiate connection to
host");

// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");

// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'],
$workDir."/".$tmpName, FTP_BINARY);

// check upload status
// display message
if (!$upload) {
  echo "Cannot upload";
} else {
  echo "Upload complete";
}

// close the FTP stream
ftp_close($conn);

// delete local copy of uploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded
file from working directory -- manual deletion recommended");
?>
[/code]
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.