Hi, I am trying to upload some files using ftp via php. I have built a function which should work as far as i can see but it isn't. Can anyone see why this would not work? function ftpupload($file, $destination){ // set up the settings $ftp_server = "ftp.".$_SESSION['domain']; $ftpuser = $_SESSION['user']; $ftppass = $_SESSION['pass']; // delete the below variables if you decide to use a form. $source_file = $file; $destination_file = $destination; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftpuser, $ftppass); ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY); // the ftp function // close the connection ftp_close($conn_id); } PHP: Then: ftpupload($rand_name.$file_ext, "/uploads/images/thumbs/"); PHP: Any Ideas? Cheers, Adam
have you tried to output the error for example print_r(ftpupload($rand_name.$file_ext, "/uploads/images/thumbs/")); and please check if a connection is created by using if ($login_result !== false) { // the rest }
Right i have given up doing it that way, i have however found a way that does upload but when the file is uploaded on the server it is 0kb but at least it is uploading. function ftpupload($file){ $ch = curl_init(); $localfile = $file; $fp = fopen($localfile, 'r'); curl_setopt($ch, CURLOPT_URL, 'ftp://'.$_SESSION['name'].':'.$_SESSION['pass'].'@87.229.14.87/httpdocs/uploads/images/thumbs/'.$file); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); curl_exec ($ch); $error_no = curl_errno($ch); curl_close ($ch); if ($error_no == 0) { print 'File uploaded succesfully.'; } else { print 'File upload error.'; } } PHP: Any Ideas why it is 0kb?