Faint Posted May 5, 2008 Share Posted May 5, 2008 Hey. Please don't tell me now things like: Use Google! ...I've been searching up my problem on google for hours... I found lots of stuff, i really don't get. I NEVER used PHP...only HTML... So here is my problem: What I need: A Upload button, and an ...whats the word (I'm german...) ...a field, to chose files to upload... I need all this for my job... The sense is, that ANYONE can upload files to my FTP server... _______________________________________________________________ so could please someone give me a script? or a link... sorry, i really dont get it to work... My FTP server is: FaintFTP.fa.ohost.de Username: FaintFTP Password: 123456789 (not really, just for example!) could please someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/ Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 So you need a web page that allows users to upload files to an FTP server? Is the web page that allows users to upload files on a server that is different from your FTP server? What you can do is use a file upload form like this: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> And then you can upload the file to the server that is hosting the file upload page. There is a tutorial for doing that here: http://www.tizag.com/phpT/fileupload.php Then, using the PHP FTP functions http://us3.php.net/manual/en/ref.ftp.php , you could transfer the file to your FTP server. Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-533663 Share on other sites More sharing options...
Faint Posted May 5, 2008 Author Share Posted May 5, 2008 Uhm...Thanks so far I tried EXACTLY these 2 links before...i found both in google... think i will ned a php-file and an html-file (form.) for the upload The Form is included in my webpage... so there will be a index.html (my webpage (Including the formular for the uplaod) and a uploader.php Both are placed in the folder Faintftp.fa.ohost.de/HP/... _______________________________________________________________________________ hm... like I told you, i tried both. but i never used php, so i don`t get, this... Could you please create something like this for me? Plzzz Start a new php file with the script you told me to. (Use as FTP-Address: Faintftp.da.ohost.de - name: FaintFTP - pass: 123456789) and a second one a Index.html, which includes only the html code for the form... (A submit button, and a field with a "Browse" button.) Then upload it here as Attachment... Please could anyone do this for me? Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-533755 Share on other sites More sharing options...
RichardRotterdam Posted May 5, 2008 Share Posted May 5, 2008 dude seriously dont place passwords. and besides i think your searchin for simply uploading a file to your server you dont need a ftp protocol for that try searching without the ftp Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-533762 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 Is the file going to be uploaded on the SAME server that the form/php are going to be hosted on? Or are they not? Tell me and I'll write a script for you. Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-533770 Share on other sites More sharing options...
Faint Posted May 6, 2008 Author Share Posted May 6, 2008 thanks so much...i`ve asked in about 4 or 5 forums, and you gave the best help...till now On the same server will be: - Index.html (My Homepage including the form for the upload) - If needed a uploader.php (or something like this (Yes, its located on the same server, where files will be uploaded!)) - a folder called "Uploads" (the uploaded files, (only PNG, Jpeg, and Gif) should be in there!) I think thats all on information i think...(Max Size should be 4mb) Oh, wait... In a tutorial on how to write this script, i read that a file, that has been uploaded to my server, will be deleted if its not moved to another folder... Could you please write the script so, that the files will be moved directly to another folder on my server (name doesnt matter) any questions? (PLZZZ HELP ME!) €dit: Oh yes, and a form like this would be cool...(or exactly this, change only allowed size to 4mb and allowed format to jpg, png and gif) ---------------------------------------- <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> ---------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-534336 Share on other sites More sharing options...
Faint Posted May 9, 2008 Author Share Posted May 9, 2008 *push* Dark water...u said you will help me...please by the way... (why "am I not allowed to send personal Messages"?) Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-536816 Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 This is quite easy actually... let me go get my information I have on the subject.. <-- 2 minutes later --> This is for a one file upload script. First off we'll need a form: This is just a simple form.. <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> Then below all this is where we need our PHP... <?php $uploadDir = 'C:/webroot/upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } echo "<br>Files uploaded<br>"; } ?> That is basically it... Then if you want to handle duplicate file names, you can do something like this instead of the code above.. <?php $uploadDir = 'C:/webroot/upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } echo "<br>Files uploaded<br>"; } ?> And there ya go, simple and sweet upload form... here is a sample of the entire code. <html> <head> <title>Upload File</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .box { font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } --> </style> </head> <body> <? // you can change this to any directory you want // as long as php can write to it $uploadDir = 'C:/webroot/upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // generate the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } echo "<br>File uploaded<br>"; } ?> <form action="" method="post" enctype="multipart/form-data" name="uploadform"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> </body> </html> I hope this helps you a little. Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-536842 Share on other sites More sharing options...
richardw Posted May 9, 2008 Share Posted May 9, 2008 Here is an ftp solution, useful if you want ownership to show instead of "nobody". This example will post your uploaded file into a database for later use. <?php if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){ $local_file = $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded $destination_file = "/public_html/YourDomain/docs/".($_FILES['txt_file']['name']); // $destination_file = "/recreation/images/".basename($_FILES['txt_file']['name']); // Path for File Upload (relative to your login dir) // Global Connection Settings $ftp_server = "address_see_note_at right"; // FTP Server Address (exlucde ftp://) $ftp_user_name = "user_here"; // FTP Server Username $ftp_user_pass = "pass_here"; // Password // Connect to FTP Server $conn_id = ftp_connect($ftp_server); // Login to FTP Server $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // Verify Log In Status if ((!$conn_id) || (!$login_result)) { // echo "FTP connection has failed! <br />"; // echo "Attempted to connect to $ftp_server for user $ftp_user_name"; // exit; } else { // echo "Connected to $ftp_server, for user $ftp_user_name <br />"; } $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY); // Upload the File // Verify Upload Status ?> <?php if (!$upload) { $message = "<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />"; } else { $link = "http://www.domainname_here.com/docs/".$_FILES['txt_file']['name']; $file_name = $_FILES['txt_file']['name']; // </font><br /><br /><br /><br />"; $message = "Success!<br /><br />" . $_FILES['txt_file']['name'] . " has been uploaded to " . $ftp_server . $destination_file . "!<br /><br />"; $title = $_POST["title"]; $description = $_POST["description"]; $category = $_POST["category"]; // Connect to Database include "db_conn.php"; $sql = "INSERT INTO docs ( title,link,filename,description,category) VALUES ('$title','$link','$file_name','$description','$category')"; $result = mysql_query($sql); } ftp_close($conn_id); // Close the FTP Connection } ?> and my form is: <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data"> Please choose a file: <input name="txt_file" type="file" size="35" /><br /> <br /> File Title: <input name="title" type="Text" size="62"> <br /> <br /> Description: <input name="description" type="Text" size="62"><br> <br> Category: <select name="category"> <option value=""> - Select - </option> <?php include "db_conn.php"; $sql2 = "SELECT * FROM cat ORDER BY category ASC"; $result2 = mysql_query($sql2); while ( $row2 = mysql_fetch_assoc( $result2)) { echo "<option value=\"".$row2["cat_id"]."\">".$row2["category"]. "</option>\n"; } mysql_free_result($result2); ?> One important item that I forgot to mention: The PHP code for the ftp upload must appear at the top of the page before the 'DOCTYPE' line. best Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-536896 Share on other sites More sharing options...
Faint Posted May 10, 2008 Author Share Posted May 10, 2008 hmmm I tried the one radar gave to me... -------------------------------------------- $uploadDir = 'C:/webroot/upload/'; -------------------------------------------- should I change this? My FTP is FaintFTP.fa.ohost.de and...I pasted the codes into an empty html file. I tried to upload> It said "File Uploaded!" >but I cant find the uploaded file...where is it now? Is it possible to move it to Faintftp.fa.ohost.de/Host/Uploads/ Thx (Sorry, I'm a beinner in php...but not in html...) Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-537410 Share on other sites More sharing options...
Faint Posted May 11, 2008 Author Share Posted May 11, 2008 YIPIIIEEHHHHH... Thacks to all of you guys, u'r all great! The one, Radar gave me worked! Thanks so much! ahm one more question: --------------------- echo "<br>Files uploaded<br>"; --------------------- Is it possible to display this in red? <font COLO="red"> </font> doesnt work! Quote Link to comment https://forums.phpfreaks.com/topic/104237-upload-via-ftp/#findComment-538193 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.