Jump to content

FTP Upload a File


bobdole

Recommended Posts

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?

Link to comment
Share on other sites

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 by cpd
Link to comment
Share on other sites

 

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 :/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

Thanks for the replies. 

@teynon

Thanks 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.

Link to comment
Share on other sites

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 by cpd
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.