Forum Moderators: coopster
I can write a simple PHP script that will accept file uploads from a user submitted HTML form. Then have the script rename and move the file to a specific directory.
why then, or when would, i need to use FTP? I guess I'm not very familiar with the protocol.
Thanks!
You can use PHP's filesystem functions like
copy()and
unlink()to do whatever you want in your own filesystem, as long as permissions are set correctly. Very rarely indeed will you want to use PHP's ftp functions to manipulate files on your own server - this is sort of like telephoning somebody who's in the same room. The ftp functions aren't an ftp server themselves, they're there to communicate with ftp servers (provide 'client access'), including the ftp server on your own server (telephoning inside your own room). FTP means 'file transfer protocol' - files on your own server are already on your own server, so they don't need to be 'transferred' there - they only need to be moved about.
For more info on doing file uploads see [be2.php.net...] and click on the links to the functions involved.
Let's suppose I have a client (person) who runs a product inventory database on an AS400. He can export the data to a text file and I want to allow him to transfer the file to mysql using a web-based HTML form on the company's website. (he does not know how to use PMA or mysql from the command line and should not have to)
The thing to do would be for the user to upload the text file (without having to use an FTP client such as CuteFTP) and then my php script will parse the data and stick it in the database. The goal is to make it easy for the user.
Someone suggested that I use php's ftp function for the txt file upload. I was thinking use php's file management functions like copy(), move(), rename(), et al.
Thanks again .
The link above will show you how to write an upload script just based on an html form. HTTP already contains the means for file uploads, so you don't have to use ftp. If the link above is a bit challenging, try googling 'php file upload script tutorial' or something like that.