Forum Moderators: coopster

Message Too Old, No Replies

a script to handle file uploads or ftp

total noobie question

         

mgm_03

2:20 am on Nov 2, 2004 (gmt 0)

10+ Year Member



I'm sure this is a pretty easy question ...

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!

coopster

3:49 am on Nov 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How would you get the PHP file upload script to the server in the first place? ;)

mgm_03

4:41 am on Nov 2, 2004 (gmt 0)

10+ Year Member



I would obviously ftp the script.

But I can't assume that the FTP option is enabled in PHP, right?

So, using PHP's FTP functions may not always work.

Why not just use <form enctype="multipart/form-data"....> ...</form> along with a processing script for user submitted files?

mincklerstraat

9:23 am on Nov 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@ coopster: chicken - or - egg trolling?
;)
@mgm_03:
You usually use ftp to upload your scripts to the server before you can use them there. PHP doesn't have to have ftp enabled to do this, it has nothing to do with PHP.

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.

mgm_03

2:34 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



i appreciate the responses. i may not be explaining myself well.

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 .

pete_m

2:41 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



mgm_03: You are right to use your PHP upload script - use a HTML form to upload the text file.

The FTP functions in PHP allow a script to act as an FTP *client* - i.e. to access remote FTP servers.

mincklerstraat

9:39 am on Nov 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



like pete_m says, for this one, the ftp functions really won't help you - in order to use them, the user would have to already have uploaded the files to an ftp server which your script can access, and that really would be the aweful-round-about way of doing it.

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.

coopster

12:29 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't want to take this off topic, but has your client considered getting the data directly from the AS/400? Why go through the extra step of exporting and importing data on a regular basis? No need for an answer, just a consideration for you...