Reputation: 21
I'm trying to upload a single file to my ftp directory but unable to upload the file. I keep getting the following error
Warning: ftp_put() expects parameter 3 to be a valid path, array given
<form action="" class="tsc_form_contact_light frame tbar" method='post' enctype="multipart/form-data">
<label for="name">ArtWork Name <font color='red'>(required)</font></label>
<input type="upload" name="artname" class="form-input" required />
<label for="name">ArtWork Image</label>
<input type="file" id="uploadfile" name="uploadfile">
</form>
$path_of_storage = '/public_html/newinvoice/orderimage/';
$newftpdir = $_SESSION['SESS_ORDER_ID'];
$conn_id = ftp_connect($ftpserver);
ftp_pasv($conn_id, true);
$login_result = ftp_login($conn_id, $ftplogin, $ftppass);
//ftp_mksubdirs($conn_id,$path_of_storage,$newftpdir);
$source_file = $_FILES['uploadfile']['tmp_name'];
$destination_file = "$path_of_storage".$source_file;
$destination = "$path_of_storage";
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
$name = $_FILES["uploadfile"]["name"];
move_uploaded_file($source_file, "$destination/$name");
// check upload status
if (!$upload) {
echo "FTP upload has failed! $destination_file";
} else {
echo "Uploaded $source_file as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
Upvotes: 0
Views: 1846
Reputation: 2512
$_FILES contains array of all the uploaded file along with the attributes like name, type, tmp_path etc
Use $_FILES['uploadfile']['tmp_name'] for the file path
Refer to this link for more details
Upvotes: 1