Jump to content


Photo

uploading files to ftp using php(help)


  • Please log in to reply
1 reply to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 August 2006 - 05:51 PM

<?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");
?>


#2 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 August 2006 - 05:58 PM

need a lil help with upoloding files with php
$host = "localhost";
is that right do i put localhost or ftp://aaasas..asdds.com
srry never done this before




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users