1

I am trying to upload a photo to my ftp server. Here is te html code:

<html>
<body>
<form enctype="multipart/form-data" action="db.php" method="POST">
Choose a file to upload:
<input name="file" type="file" />
<br/>
<input type="submit" value="Upload File" />
</form>
</body>
</html>

And it is my php code:

<?php
$ftp_server="myserver";
$ftp_user_name="username";
$ftp_user_pass="pass";
$file = $_FILES['file']['name'];
$remote_file = "x.png";
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$upload = ftp_put($conn_id, $remote_file, $file, FTP_ASCII);
if(move_uploaded_file ($file , "/photos")) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
ftp_close($conn_id);
?>

but when i trying to upload a file it show an error like:

Warning : ftp_put(o.png) [function.ftp-put ]: failed to open stream: No such file or directory in /home/ a1268559/public_html/ profile/db.php

Please help me

1 Answer 1

2

You have to do move_uploaded_file first before ftp_put

also move_uploaded_should be like this

move_uploaded_file ($file , "/photos/$filename");

then your ftp_put would be like

$upload = ftp_put($conn_id, $remote_file, "/photos/$filename", FTP_ASCII);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.