Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp_put - adsolute path or relative

Status
Not open for further replies.

tobyheywood

IS-IT--Management
Apr 20, 2001
122
GB
Hi all,

I'm in the process of creating a script which will be used to upload an image from a webcam every 5-10 seconds to our web server.

The script so far works when I run the script from within the same directory as the file I want to upload, but not when I run it from my home directory. I am running the script as root so don't believe it is a perms issue.

The script can determine the most up to date file from the sym link in the relevant directory, so it would seem that it can't upload unless the file to be upload is in the same directory.

I would be greatful of any advice or suggested ways of getting around this.

Code:
$connid = ftp_connect($ftpserv);
$login = ftp_login ($connid, $ftpuser, $ftppass);

if (!$connid || !$login) {
	echo 'Failed to connect to server\n';
} else {
	echo "Connected to $ftpserv as $ftpuser\n";
}

foreach ($Camera as $val) {
	$camdir = $val['LocalDir'];
	$remdir = $val['RemoteDir'];

	$upload_file = readlink ($camdir . 'lastsnap.jpg');

	$ftp_upload = ftp_put($connid, $remdir . 'lastsnap.jpg', $upload_file, FTP_BINARY);
	
	if ($ftp_upload) {
		echo "Successfully uploaded file: $upload_file\n";
	} else {
		echo "Unable to upload file: $upload_file\n";
	}
}

ftp_quit($connid);

Toby Heywood

 
What is your lastsnap.jpg symlink pointing to? I believe readlink() only returns an absolute path if the symlink itself points to an absolute path. So if your symlink is pointing to a relative path, i.e. just an image file name, then that would explain why it only works in your images directory.
 
AdaHacker,

You are a genius! I think next time I decided to do any coding I'll try it with my eye's open.

It was so simple, I missed it.

Thanks again.

Regards

Toby Heywood

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top