tamileelam Posted September 7, 2007 Share Posted September 7, 2007 Hi! I tried to upload a file from one pc to another pc using PHP. I didnt able to upload that file. But, I was able to upload a file to FTP or local directory. Can you provide the PHP script for upload a file to remote PC?. I have attached the sample code. Please correct that code. Thank you verymuch! Tamileelam. SourceCode : upload.html ---------------------------------- <html> <head></head> <body> <h2>Please provide the following information:</h2> <form enctype="multipart/form-data" method="post" action="upload.php"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> Host <br /> <input type="text" name="host" /><p /> Username <br /> <input type="text" name="user" /><p /> Password <br /> <input type="password" name="pass" /><p /> Destination directory <br /> <input type="text" name="dir" /><p /> File <br /> <input type="file" name="file" /><p /> <input type="submit" name="submit" value="Upload File" /> </form> </body> </html> SourceCode :upload.php ------------------------------- <?php // get FTP access parameters $host = $_POST['host']; $user = $_POST['user']; $pass = $_POST['pass']; $destDir = $_POST['dir']; $workDir = "C:/"; // define this as per local system // get temporary file name for the uploaded file $tmpName = basename($_FILES['file']['tmp_name']); // copy uploaded file into current directory move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName) or die("Cannot move uploaded file to working directory"); // open connection $conn = ftp_connect($host) or die ("Cannot initiate connection to host"); // send access parameters ftp_login($conn, $user, $pass) or die("Cannot login"); // perform file upload $upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'], $workDir."/".$tmpName, FTP_BINARY); // check upload status // display message if (!$upload) { echo "Cannot upload"; } else { echo "Upload complete"; } // close the FTP stream ftp_close($conn); // delete local copy of uploaded file unlink($workDir."/".$tmpName) or die("Cannot delete uploaded file from working directory -- manual deletion recommended"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68305-how-do-upload-a-file-from-one-pc-to-another-pc-using-php/ Share on other sites More sharing options...
teng84 Posted September 7, 2007 Share Posted September 7, 2007 what do you mean move upload file uploads the file on the server where ever in the world you want to get that file Quote Link to comment https://forums.phpfreaks.com/topic/68305-how-do-upload-a-file-from-one-pc-to-another-pc-using-php/#findComment-343428 Share on other sites More sharing options...
cooldude832 Posted September 7, 2007 Share Posted September 7, 2007 Php can integrate into ftp commands to create what you looking for. Quote Link to comment https://forums.phpfreaks.com/topic/68305-how-do-upload-a-file-from-one-pc-to-another-pc-using-php/#findComment-343430 Share on other sites More sharing options...
tamileelam Posted September 7, 2007 Author Share Posted September 7, 2007 Php can integrate into ftp commands to create what you looking for. Hi! I have some files in my local directory. I want to upload those files in to my remote PC using PHP script. Regards tamileelam Quote Link to comment https://forums.phpfreaks.com/topic/68305-how-do-upload-a-file-from-one-pc-to-another-pc-using-php/#findComment-343441 Share on other sites More sharing options...
cooldude832 Posted September 7, 2007 Share Posted September 7, 2007 Why? if you can ftp it achieves the same. Quote Link to comment https://forums.phpfreaks.com/topic/68305-how-do-upload-a-file-from-one-pc-to-another-pc-using-php/#findComment-343447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.