I have a script to upload files via FTP to an external server through PHP, which is generating errors and even if it changes to the passive port, or from FTP_Binary to Ascii or inverse, keeps generating errors.
When putting ftp_pasv () , the error still appears and the following is added
error:
Many ports are generated in Apache, the same for hosting, so the problem would not be in the local xampp, but, it is general.
The script returns this error:
'PORT' Command not implemented
, and when I put the passive mode of php, it returns this:
Fatal error: Maximum execution time of 30 seconds exceeded in
and the extra ports.
my code
<?php
include("db.php");
function upload($file, $author){
$id = mt_rand(100000, 999999);
$format = pathinfo($file, PATHINFO_EXTENSION);
$db = dbConnect();
$save = $db->prepare("INSERT INTO files (id, author, format) values (:id, :author, :format)");
$save->bindParam("id", $id);
$save->bindParam("author", $author);
$save->bindParam("format", $format);
$save->execute();
$conn_id = ftp_connect("servidor") or die ("Cannot connect to host");
ftp_login($conn_id, "pwd", "pwd") or die("LOGIN ERROR");
ftp_pasv($conn_id, true);
$upload = ftp_put($conn_id, $id.$format, $file, FTP_BINARY);
return $id;
}
upload("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg", "912198");
?>