Thursday 15 April 2010

mysql - Uploading image to FTP using PHP -



mysql - Uploading image to FTP using PHP -

i have tried files upload server using ftp connection in php , not working, connecting getting error "connected xxxxxxxxxxx, user xxxxxxxxxxxxx ftp upload has failed!" have tried next code please help correcting it,..

image.html

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title>welcome</title> </head> <body> <form action="upload.php" enctype="multipart/form-data" method="post"> <input name="file" type="file" /> <input name="submit" type="submit" value="upload file" /> </form> </body> </html>

upload.php

<?php $ftp_server = "xxxxxx"; $ftp_user_name = "xxxxxxx"; $ftp_user_pass = "xxxxxxxx"; $destination_file = "imagetest/123/".$_files['file']['name']; $source_file = $_files['file']['tmp_name']; // set basic connection $conn_id = ftp_connect($ftp_server); ftp_pasv($conn_id, true); // login username , 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!"; echo "attempted connect $ftp_server user $ftp_user_name"; exit; } else { echo "connected $ftp_server, user $ftp_user_name"; } // upload file $upload = ftp_put($conn_id, $destination_file, $source_file, ftp_binary); // check upload status if (!$upload) { echo "ftp upload has failed!"; } else { echo "uploaded $source_file $ftp_server $destination_file"; } // close ftp stream ftp_close($conn_id); ?>

i've tested code , had bit of hard time working, worked me utilize /http_docs, or /public_html base/root folder.

root folder names vary hosting services, modify accordingly.

i.e. , few modifications:

<?php $ftp_server = "xxxxxx"; $ftp_user_name = "xxxxxxx"; $ftp_user_pass = "xxxxxxxx"; $folder = "/http_docs/imagetest/123/"; $destination_file = $folder . $_files['file']['name']; $source_file = $_files['file']['tmp_name']; // rest of code

sidenote:

do not utilize total path name.

i.e.: /var/user/you/public_html/ won't work.

php mysql file-upload upload ftp

No comments:

Post a Comment