Click to See Complete Forum and Search --> : ftp_get, ascii / binary


JehovahsWord
09-16-2003, 03:26 PM
hi,

like I said before, I am making an ftp script. but now I'm making a part where the person can upload files. I read the php manual about ftp_get, and it said there are four necessary parts of the ftp_get functions. those being: resource id,, remote file, local file, and the mode. for the mode part, it said to use either FTP_ASCII or FTP_BINARY. I did, and I got an error. it basically said I wasn't allowed to give a string for the fourth parameter. so, I tried using integers. and then it uploaded successfully. my question is, is this the correct way to do this? and why does the php manual mention FTP_ASCII and FTP_BINARY? and, if you are suppose to use integers, is 0 for ascii and 1 for binary? thanks

Brandon

Kr|Z
09-17-2003, 10:58 AM
Make shure you write it without quotes.

FTP_BINARY and not "FTP_BINARY"

JehovahsWord
09-17-2003, 02:51 PM
hi,

I didn't use quotes, but I used a variable. Here is a snippet of my code.


echo "<ul>\n";
foreach ($fileupload as $val) {
if (!empty($val)) {
$filename = basename($val);
if (ftp_put($conn_id, $dir."/".$filename, $val, $mode)) {
echo "<li>successfully uploaded ".$filename."</li>\n";
} // end if
else {
echo "<li>failed uploading ".$filename."</li>\n";
} // end if
} // end if
} // end foreach
echo "</ul>\n";


the basename takes the actually file name from the path of the file they are trying to upload. but anyway as you see $mode is not in quotes. I suppose I could do something like this:


if ($mode == "FTP_ASCII") {
$mode = FTP_ASCII;
}
else {
$mode = FTP_BINARY;
}


would that work?

Brandon

Originally posted by Kr|Z
Make shure you write it without quotes.

FTP_BINARY and not "FTP_BINARY"

Kr|Z
09-17-2003, 03:10 PM
Sorry... I tried it out myself, and both

ftp_put($ftp, $file, $file, FTP_BINARY);

and

ftp_put($ftp, $file, $file, "FTP_BINARY");

worked for me...