I am working on a self taught local project and trying to upload a file to a server.
but when I upload the image file it gets corrupted.
this is my upload.php
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads'; //2
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
$ftp_server="myServer";
$ftp_user_name="userName";
$ftp_user_pass="Password";
$file = $targetFile;//tobe uploaded
$remote_file = $_FILES['file']['name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
}
?>
It currently uploads to the local folder Uploads
also to the server but corruptted any help on this will be great.
Have you tried using FTP Binary? an image is a binary file not an ASCII file.