mhenderson00 Posted November 11, 2006 Share Posted November 11, 2006 Hi all!I have an upload.php program that uses ftp_put to connect to ftp and upload files.I am able to connect and upload files. However, I am able to upload files FROM the directory my php program is running TOthe same server. I want to ftp a remote file uploaded through my webpage.When I cature the filename in a form and use that filename as the FROM file, I get an ftp error??'How do I use FTP to oupload a file from my laptop for example, through my webpage onto my server?'Please let me know if you need more infoThanks in advance Link to comment https://forums.phpfreaks.com/topic/26891-ftp-issue/ Share on other sites More sharing options...
marcus Posted November 11, 2006 Share Posted November 11, 2006 Post the script. Link to comment https://forums.phpfreaks.com/topic/26891-ftp-issue/#findComment-122964 Share on other sites More sharing options...
mhenderson00 Posted November 11, 2006 Author Share Posted November 11, 2006 <html><title> </title></html><?phpfunction display_info($filename,$video_title,$video_desc,$video_cat){?> <p align="center">The file <i><b> <?print basename( $_FILES['uploadedfile']['name']); ?> </b></i> has been uploaded </p><br><br> <p align="center"><b>Video Title:</b><?print $video_title;?><br><b>Video Description:</b><?print $video_desc;?><br><b>Video Category:</b><? print $video_cat; ?></p><?}function display_home(){ ?> <body link="#000000" vlink="#000000" alink="#000000"> <p align="center"> </p> <p align="center"> </p> <p align="center"><b><font face="Palatino Linotype" size="6"> <a href="/michelle">HOME</a></font></b></p></body> <?}function insert_db($filename,$video_title,$video_desc,$video_cat){ $username = ""; $password = ""; $hostname = ""; $dbh = mysql_connect($hostname, $username, $password) or die("Error Connecting"); $selected = mysql_select_db("",$dbh) or die("Error Accessing Database"); $insert = mysql_query("INSERT INTO video VALUES('$filename','$video_title','$video_desc','$video_cat','mhenderson' )"); if (!$insert) { die("Error Inserting "); } else { return true; }} $ftp_server = ""; $ftp_user_name = ""; $ftp_user_pass = ""; $video_title = $_POST['video_title']; $video_desc = $_POST['video_desc']; $video_cat = $_POST['video_category']; $filename = $_FILES['uploadedfile']['name']; $target_path = "../../michelle/" . basename( $_FILES['uploadedfile']['name']); echo "<br>".$target_path; $error_mess ="There was an error uploading the file:". basename( $_FILES['uploadedfile']['name']).", please try again"; $success_mess = "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; $dup_mess ="Filename:". basename( $_FILES['uploadedfile']['name']); if (file_exists($target_path)) { echo "<p align=center><b>File <i>". $target_path ."</i> Already Exists."."</p></b>" ; display_home(); } else { if(insert_db($filename,$video_title,$video_desc,$video_cat) == true) { $conn_id = ftp_ssl_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!"; print $error_mess; display_home(); } else { ftp_pasv($conn_id, true); echo "PASV: On\r\n"; echo "Connected to $ftp_server, for user $ftp_user_name<br>"; echo $target_path; echo " ".$filename." "; $getfile = "../".$dir."/temp.txt"; echo "<br>".$target_path; $local_file = "/temp.txt"; $upload = ftp_put($conn_id, $target_path, '../../michelle/uploads/temp.txt', FTP_BINARY); // upload the file if (!$upload) { // check upload stat echo "FTP upload has failed!"; display_home(); } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; display_info($filename,$video_title,$video_desc,$video_cat); echo "<p align=center><b>Type: </b>" . $_FILES['uploadedfile']["type"] . "</p>"; echo "<p align=center><b>Size: </b>" . ($_FILES['uploadedfile']["size"] / 1024) . " Kb</p><br>"; display_home(); } // close the FTP stream ftp_close($conn_id); } } else { print "Could not insert into DB"; }} ?> michelle is the directory my uploader.php is in. If I try to use the $filename (from the file selected to upload from form) it won't work, I even tried to put the directory in manually (ie C:/temp.txt). The only time I am successful seems when I upload a file from michelle to somewhere on my same server, since the form is calling a program on my server and I am ftp to my server, it seems I am ftp to myself??? I'm new at this sorry :) how do i create an ftp from my a file on my remote computer, through this program to my websever? Link to comment https://forums.phpfreaks.com/topic/26891-ftp-issue/#findComment-122975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.