FTP upload failed

I have the following simple script. But I am getting the error message "FTP
upload failed!" Which is annoying. Why might this be ?

the files i have tried are tiny .txt and jpeg.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
</head>
<?php
$upload = False;
if (array_key_exists('submit',$_POST))
{
$message = "";

$file = $_FILES['uploaded']['name'];

$ftp_server ="details removed";
$ftp_user_name = "details removed";
$ftp_user_pass ="details removed";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result))
{
echo "FTP connection has failed!<br>";
echo "Attempted to connect to $ftp_server for user
$ftp_user_name<br>";
exit;
}
else
{
echo "Connected to $ftp_server, for user $ftp_user_name<br>";
}

// upload the file
$upload = ftp_put($conn_id, $file, $file, FTP_ASCII);

// check upload status
if (!$upload)
{
echo "FTP upload has failed!<br>";
}
else
{
echo "Uploaded $source_file to $ftp_server as $file<br>";
$upload = True;
}

// close the FTP stream
ftp_close($conn_id);

}
?>
<body>
<?php if (!$upload) {?>
<p>Browse to the document you would like to upload.</p><form
enctype="multipart/form-data" method="post">
<input name="uploaded" type="file" /><br>
<input type="submit" name="submit" value="GO"/>
</form>
<?php }?>
</body>
</html>
Zoe Brown [ So, 27 Mai 2007 13:37 ] [ ID #1724032 ]

Re: FTP upload failed

Zoe Brown wrote:
> I have the following simple script. But I am getting the error message "FTP
> upload failed!" Which is annoying. Why might this be ?
>
> the files i have tried are tiny .txt and jpeg.

> $upload = ftp_put($conn_id, $file, $file, FTP_ASCII);
>
> // check upload status
> if (!$upload)
> {
//if you aren't going to use the $upload value, then you can use
//if(!ftp_put($conn_id, $file, $file, FTP_ASCII)) {
//instead of if (!$upload) {
> echo "FTP upload has failed!<br>";
> }
> else
> {
> echo "Uploaded $source_file to $ftp_server as $file<br>";
//no point in setting $upload to true, it's already true or
//else you would have got the "FTP upload has failed!" message
> $upload = True;
> }

It could be so that the directory whereto you come when you login to the ftp
server isn't writable for the user as you are logged in, you may have to
change to an upload directory (use ftp_chdir()).



--

//Aho
Shion [ So, 27 Mai 2007 13:46 ] [ ID #1724033 ]

Re: FTP upload failed

> It could be so that the directory whereto you come when you login to the
> ftp
> server isn't writable for the user as you are logged in, you may have to
> change to an upload directory (use ftp_chdir()).

thanks. I solved it. i was not using the correct file name, I needed to
use the temporary filename that PHP assigns on uploading from the form.
Zoe Brown [ So, 27 Mai 2007 13:59 ] [ ID #1724034 ]
PHP » alt.php » FTP upload failed

Vorheriges Thema: How to add and retrieve data from an SQL database on the hosting site
Nächstes Thema: hosting recomendations