bobdole Posted June 5, 2013 Share Posted June 5, 2013 Hey guys, I've searched this and couldn't find a way to do it that works. I'm looking for a form, that has a file upload button and a submit button. Once the user clicks submit, the selected file gets uploaded on the users ftp. I'm using godaddy as my hosting. Does anyone know how to approach this? Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/ Share on other sites More sharing options...
litebearer Posted June 5, 2013 Share Posted June 5, 2013 http://www.tizag.com/phpT/fileupload.php Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434288 Share on other sites More sharing options...
cpd Posted June 5, 2013 Share Posted June 5, 2013 (edited) You don't upload files to the "FTP". The File Transfer Protocol (FTP) is a means of accessing files held on a machine (often a server). All you want to do is upload the files to the host and ensure the files are put into a folder the users FTP account has access to. Edited June 5, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434292 Share on other sites More sharing options...
bobdole Posted June 5, 2013 Author Share Posted June 5, 2013 http://www.tizag.com/phpT/fileupload.php This site was very useful, I tried out the entire tutorial. I am not sure I understand though. To upload a file to my server, I don't even need my FTP login or password? Is that correct? You don't upload files to the "FTP". The File Transfer Protocol (FTP) is a means of accessing files held on a machine (often a server). All you want to do is upload the files to the host and ensure the files are put into a folder the users FTP account has access to. Yes, that is what I am trying to do. Using php, I want to upload a few images to my server in the directory "code-crash.com/uploads" or "root/uploads' I am still getting many errors though :/ Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434299 Share on other sites More sharing options...
cpd Posted June 5, 2013 Share Posted June 5, 2013 Saying you have lots of errors will get you absolutely no-where. In-fact, you may even go backwards it is that unhelpful. Try explaining, in detail, what you've attempted and provide code snippets. Include what debugging steps you've carried out on your own initiative (if any) and then we can hep you from there. Ultimately, you want a PHP File Upload system and making a basic one probably takes less than 50 lines of code. Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434325 Share on other sites More sharing options...
teynon Posted June 5, 2013 Share Posted June 5, 2013 This site was very useful, I tried out the entire tutorial. I am not sure I understand though. To upload a file to my server, I don't even need my FTP login or password? Is that correct? Yes, that is what I am trying to do. Using php, I want to upload a few images to my server in the directory "code-crash.com/uploads" or "root/uploads' I am still getting many errors though :/ On a browser, at least last time I checked, you don't get to choose "FTP" as an upload option. There are some Java Applet FTP upload options. However, I will not post links. Because once I do, this thread will continue with questions on how to implement that. As for File Uploads in PHP, i'll keep posting this library: http://blueimp.github.io/jQuery-File-Upload/ Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434326 Share on other sites More sharing options...
bobdole Posted June 6, 2013 Author Share Posted June 6, 2013 Thanks for the replies. @teynonThanks for the help, and that link seems like a useful program. Although it seems a little to big for the simple program I am trying to implement. @cpd I'm not communicating very clearly, so I will be more precise with my comments. I actually don't have many errors. What I should have said was I have questions and not errors. I'm not sure how to approach the situation is what I am trying to say. I'll explain what I am trying to do: I have an html form where I upload a file and it does unrelated stuff to my website on submit. I am only uploading pictures. I was hoping to add another function that also puts the image I just submited online on my site. The directory is "mysite/images/" I get a broken image when I try to look at the image, so I have to go into my filezilla and upload the image manually. Everything works then, but the problem is I upload many images at a time and I wish to make things quicker. Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434357 Share on other sites More sharing options...
cpd Posted June 6, 2013 Share Posted June 6, 2013 (edited) You upload a file and it does "unrelated stuff to your website" - that doesn't really make sense. You mean you have a form used for uploading files and the files don't affect your website in any way once uploaded? Putting an image online is as simple as moving it, once uploaded, to the public directory or a sub directory in the public directory; the move_uploaded_file function will do this for you. You then just need to submit a URL with the correct path to view it in your browser. E.g. If you upload a file to "/home/myaccount/public_html/images/foo.png" you should access it from "domain.com/images/foo.png". Edited June 6, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434358 Share on other sites More sharing options...
bobdole Posted June 6, 2013 Author Share Posted June 6, 2013 So it's looking like I don't even need to use my ftp account. Awesome. You upload a file and it does "unrelated stuff to your website" - that doesn't really make sense. You mean you have a form used for uploading files and the files don't affect your website in any way once uploaded? Most people don't like to many details, but I see you are not one of them. I was just worried I would scare people off and cause them not to answer with a length post. So here is my code now: <html> <head> </head> <body> <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> </body> </html> This code links to "uploader.php" which is here: <?php // Example of accessing data for a newly uploaded file $fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // Path and file name $pathAndName = "images/".$fileName; // Run the move_uploaded_file() function here $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); // Evaluate the value returned from the function if needed if ($moveResult == true) { echo "File has been moved from " . $fileTmpLoc . " to" . $pathAndName; } else { echo "ERROR: File not moved correctly"; } ?> I am trying to use a file chooser to grab the image name. I keep getting: ERROR: File not moved correctly Any help would be awesome! I'm so close. Quote Link to comment https://forums.phpfreaks.com/topic/278816-ftp-upload-a-file/#findComment-1434508 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.