Reputation: 9
I can upload images to our website no problem, in particular a generated QR code. I use the code to follow an ordered product and match it to the printed personalised message that also has the same QR code. If both QR codes do not match, I either have the wrong product or wrong personalisation to add, has saved me many a time from shipping wrong item with wrong personalisation!
Currently use FILEZILLA to manually download all the generated QR codes to work PC so another process adds the .png image to the printed personalisation.
I thought I would create a simple PHP to automate this process and I have hit a total inexplicable error, it connects, I can see files in folder, I can change the CMOD to check I have all the permissions required but for the life of me it will not download the actual .png file to my PC (client), can anybody help explain why?
Site is on a Hostgator server Running PHP 7.4, is it not possible to download a .PNG image from Server to Client PC even though Filezilla can!
<?PHP
//ERROR REPORTING ON, NO ERRORS SHOW AT ALL
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$qrcodigo1="3574975711.png"; // FILENAME I WANT TO TRANSFER
$source_file = "$qrcodigo1"; //ASSIGN TO SOURCEFILE STRING.
$destination_file = "C:\Users\*USER*\*MAIN-FOLDER-1*\*SUB-FOLDER-1*\*SKU-FOLDER1*\*PRODUCT-FOLDER1*\*PRODUCT-CODE-FOLDER"; // MY DESIRED HOME PC FILE LOCATION
$ftp_server = "ftp.XXXXXXXXXX.co.uk"; //SERVER
$ftp_user_name = "XXXXXX"; // USER
$ftp_user_pass = "XXXXXXXXXXXXXXXX"; //PASSWORD
// FTP CONNECTION, WORKS AND CONNECTS
$ftp = ftp_connect($ftp_server);
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
ftp_pasv($ftp, true); // SET PASSIVE TO AVOID ISSUES
if ((!$ftp) || (!$login_result)) {
die("FTP connection has failed !");
}
// CHECK IS CONNECTED BY DUMPING DIRECTORY CONTENTS - WORKS FINE
ftp_chdir($ftp, "XXX/XXXXXXXX");
echo "Connected - Current directory is now:".ftp_pwd($ftp)."<br><br>";
$file_list = ftp_nlist($ftp, ".");
var_dump($file_list);
echo "<br><br>";
// CHECK CAN MODIFY FILES TO CONFIRM FILE PERMISSIONS - WORKS FINE
if (ftp_chmod($ftp, 0777, $source_file) !== false)
{
echo "Successfully chmoded $source_file to 777.<br><br>";
}
else
{
echo "chmod failed.<br><br>";
}
// DOWNLOAD FROM SERVER TO LOCAL PC, SAYS HAS DOWNLOADED, BUT NO FILE PRESENT?
// OUTPUT ON SCREEN SAYS "Successfully downloaded 3574975711.png to C:\Users\*USER*\*MAIN-FOLDER-1*\*SUB-FOLDER-1*\*SKU-FOLDER1*\*PRODUCT-FOLDER1*\*PRODUCT-CODE-FOLDER"
// WHERE IS FILE HEN? NO FILE IN FOLDER ??
if
(ftp_get($ftp, $destination_file, $source_file, FTP_BINARY))
{
echo "Successfully downloaded $source_file to $destination_file <br>";
}
else
{
echo "There was a problem while downloading $source_file <br>";
}
// CLOSE CONNECTION
ftp_close($ftp);
?>
Upvotes: 0
Views: 101
Reputation: 202534
While it's not completely clear from your question, the *PRODUCT-CODE-FOLDER
trailing part of the $destination_file
suggests that it's a path to a destination folder, not a file (despite the variable name).
The ftp_get
takes paths to files, not paths to folders, in both its arguments.
So this should do:
ftp_get($ftp, $destination_file . "\\" . $qrcodigo1, $source_file, FTP_BINARY)
Upvotes: 0