Problem using Uploadify along with ftp_put

Hi friends

I was going to use Uploadify for videos. While the code worked nicely for move_uploaded_file, I am having a problem with ftp_put. Below is the code of Uploadify.php, for those who know it.

Thanks for any help. I have tried to echo individual variables of ftp_put to see if there is a problem there. I don’t have one there, all the variables are printing properly.

Thanks again if anyone can solve this.

<?php
require_once '../../include/sql.php';
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/
function makeName($string){
  $str = strtr($string,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ','aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  return preg_replace('/\s+/', '', $str);
}

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

//if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetFile = IMG_LOC . $_POST['timestamp'].'-'.makeName($_FILES['Filedata']['name']);
	
	// Validate the file type
	$fileTypes = array('mp4'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	
	if (!in_array($fileParts['extension'],$fileTypes)) {
		$val =  WRONG_EXTENSION.
		echo $val;
	} else {
		//move_uploaded_file($tempFile,$targetFile);
		set_time_limit(0);
		if ($conn_id = ftp_connect(SERVER)) {
			if ($login_result = ftp_login($conn_id, FTP_LOGIN, FTP_PASSWORD)) {
				ftp_pasv($conn_id, true);
				if($ftpPut = ftp_put($conn_id, $targetFile, $tempFile, FTP_BINARY)) {
					$val = UPLOAD_SUCCESSFUL;
				} else {
					$val = UPLOAD_FAILED; // This is what I am getting
				}
			} else {
				$val = LOGIN_FAILED;
			}			
		} else {
			$val = CONNECTION_FAILED;
		}		
		ftp_close($conn_id);
		echo $val;
	}
} else {
	$val =  NULL; 
	echo $val;
}	
?>

You’re 100% certain that the below line is being evaluated?

if($ftpPut = ftp_put($conn_id, $targetFile, $tempFile, FTP_BINARY)) {

Have you checked the apache error log for any possible indication of what might be going on?

What are the values of $targetFile and $tempFile when the previous line is evaluated?

Was PHP configured with the --enable-ftp option?

http://php.net/manual/en/ftp.installation.php

Thanks for your reply oddz.

$targetFile = /var/www/domain.com/upload/1419928012-Monfilm2.mp4
$temFile = /tmp/phpsWohX3

The above is correct since with the same variables move_uploaded_file was working, that I have quoted out.

I tried to find the error log, but I don’t see that in the server. Its a custom made one, and may be they have intentionally stopped error log to be shown in the available folders of ftp ?

For --enable-ftp, how can I know if my server is configured for that, any idea ? I looked at phpinfo, don’t see that Configure Command block where --enable-ftp would have been noted. However, there is a seperate block telling FTP support is enabled.

I would begin debugging this through a separate script with bare essentials of establishing an ftp connection and placing a file on the server.

Found the solution. The target destination need to be a relative path. I was using an absolute path and hence the problem :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.