Reputation: 23
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.
Upvotes: 1
Views: 1180
Reputation: 36
First of you need to setup FileZilla
in Xampp
(this is for Windows)
Xampp
and Start FileZilla
server from the Control Panel and go to the C:\XAMPPFOLDER\FileZillaFTP
127.0.0.1
as the server name 21 as the port and the added user and password as the login detailsUpvotes: 0
Reputation: 780
$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.
Upvotes: 1