Hi
I'm having trouble using php to ftp a file from a form.
I've scoured the lists and documentation but the answer elludes me.
I put in a MAX_FILE_SIZE variable, looked in the php.ini at the tmp_dir
(left blank to default to the system temp dir), chmod to 1777 of that
temp dir. What am I not doing??
I get the error message: Warning: error opening [..'file'..]
Here's my code:
global $filename, $MAX_FILE_SIZE;
$backstr = "Back";
// An array with allowed file extensions
$allExt =
array("jpg","Jpg","JPG","gif","Gif","GIF");
$fileSize = filesize($filename);
$ftp_server="ServerNameHere";
$ftp_user_name="UserNameHere";
$ftp_user_pass="PasswordHere";
if ($fileSize > $MAX_FILE_SIZE) {
die("File size exceeds $MAX_FILE_SIZE
bytes.$backstr");
}
/* This is to isolate filename from path.
Chosen separator
"/" is for Mac and Unix-like operating
systems.
*/
$chunk_file = explode("/", $filename);
$numChunkFile = count($chunk_file);
$dstFile = $chunk_file[$numChunkFile - 1];
// Now let's get file extension
$ext = explode(".",$dstFile);
$numChunkExt = count($ext);
if (in_array($ext[$numChunkExt -
1],$allExt)) {
$ftp_id = ftp_connect("$ftp_server");
$ftp_login =
ftp_login($ftp_id,$ftp_user_name,$ftp_user_pass);
if (! $ftp_login) {
ftp_quit($ftp_id);
die("Connection failed, check your login
and password.$backstr");
}
$ftp_put_file =
ftp_put($ftp_id,$dstFile,$filename,FTP_BINARY);
if (! $ftp_put_file) {
echo "Upload failed.$backstr";
}
else {
echo "Upload $dstFile was
successful.\n";
}
}
else {
echo "ERROR - Allowed file extensions
are:\n";
for ($i = 0; $i < count($allExt); $i++) {
echo "$allExt[$i]\n";
}
echo $backstr;
}
ftp_quit($ftp_id);
}
Any help would be greatly appreciated!
Thanks,
Grant
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]