1

How do I a upload a file to xampp server using FTP and php?

<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$file = "localfile.txt";

// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
  {
  echo "Successfully uploaded $file.";
  }
else
  {
  echo "Error uploading $file.";
  }

// close connection
ftp_close($ftp_conn);
?>

Thats all I found. Can't create my own server and access it.

1
  • Have you create an FTP account on your server? You need to setup FTP properly and need to add a user before this solution works for you. Commented Dec 25, 2015 at 15:52

2 Answers 2

1
$file = "localfile.txt";
$tmp_name = $file["tmp_name"];
$name = $file["name"];
define ('SITE_ROOT', realpath(dirname(__FILE__)));  <-- Goes to current folder where your files is located.
move_uploaded_file($tmp_name, SITE_ROOT."/FOLDERTOUPLOADTO/$name");

If you want to, I can give you a script where you can use multiple input files and put them in your FTP. Just contact me in a message. And this way, you don't need the FTP login and such.

Sign up to request clarification or add additional context in comments.

1 Comment

Your welcome. Please be sure to check this as Answered if it's what you need. Else I'll try to help more :).
0

First of you need to setup FileZilla in Xampp(this is for Windows)

  1. Start Xampp and Start FileZilla server from the Control Panel and go to the C:\XAMPPFOLDER\FileZillaFTP
  2. Start The server interface
  3. Go to Edit->Users and add a new User
  4. Use 127.0.0.1 as the server name 21 as the port and the added user and password as the login details

2 Comments

when i start the server interface there is only a window to enter the host and a password and a port
Ok Good Luck with the rest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.