problem: am trying to upload a csv file into CSV folder on the hosting but it's always 0kb
had created a new ftp user account specifically upload folder with full permission
would really appreciate if you guys could help me a hand...thanks
file structure on the host:
/root
/httpdocs
/CSV
--filename.csv --- 0kb
--home.php
--uploadcsvform.php
here's the code:
<?php
// Validate file types
$allowed_filetypes = array('.csv');
// Maximum filesize at 2MB
$max_filesize = 2097152;
// Upload directory
$upload_path = './';
// Get filename
$filename = $_FILES['userfile']['name'];
// Get extension
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Settings
$host = 'ftp.********.com';
$usr = '**********';
$pwd = '**********';
$ftp_path = './filename.csv';
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('Please select a valid csv file.');
// Check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Connection
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
ftp_pasv($conn_id, true);
$upload = ftp_put($conn_id, $ftp_path, $filename, FTP_ASCII);
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload completed';
print "\n";
// close the connection
ftp_close($conn_id);
?>