Forum Moderators: coopster

Message Too Old, No Replies

Why PHP FTP

Using PHp Ftp with POST form data

         

meatch

6:18 pm on Dec 21, 2007 (gmt 0)

10+ Year Member



I have been reading the PHP.net manual, looking through posts, and I can not find any clear explanation for what is actually happening with the PHP FTP.

It seems to me that if I place a POST form on my webpage, and use it to upload a file, it is already using HTTP to upload the file to the TMP directory. It then seems redundant to use FTP to then transfer the file from the TMP directory to my destination folder.

Is it possible to get my form to submit via ftp, instead of HTTP, and then how do I get PHP to process this file upload via ftp? Or am I missing the point? Should I be approaching this in a completely different fashion?

Thanks in advance for any assistance,
Mitch

PHP_Chimp

9:32 pm on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although this is something I have never done if you want to submit a form through ftp then I guess you would use an action of "ftp:example.com" so that you get your ftp server, not the http server.

Once you have the file on your server if you want php to access them you will need to use the fopen and such to get and work with those files.

If you use the usual http action then php will have access to that file before it is uploaded to its final resting place in your file system.

If you have access to the server then you may well be able to write a shell script or some other script to run on the server directly. However php is usually running as an apache module, so is not running on the actual file system of the machine, it is running on apache.
If you are running php from the command line then you may be able to work with these files on the machine (however this is not something I have done, so im guessing :))

<edit>
Just noticed this is your first post, so welcome to Webmaster World :)

[edited by: PHP_Chimp at 9:32 pm (utc) on Dec. 21, 2007]

meatch

9:49 pm on Dec 21, 2007 (gmt 0)

10+ Year Member



Thanks for the welcome.

What your telling me confirms my assumptions. If I used FTP in the action of the form, then I would also have to supply the FTP login information (username/password), or perform some kind of weird encryption, right?

Perhaps you could help me with this instead. have you heard of anything inside of Internet Explore 6.5 or 7, that would block the use of HTTP uploads? I have a few clients that are forced to use Firefox instead - just to make my scripts work. And I can not find anything online that says why IE will not work as well.

Thanks for your help, I really appreciate it.
Mitch

henry0

10:18 pm on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the file type
have you tried striping everything (js, html etc..)
and just do one upload to verify that it works

could you post the form and the script relevant section

meatch

10:35 pm on Dec 21, 2007 (gmt 0)

10+ Year Member



Hello HenryO,

The script works great from my computer (PC and Mac), just some clients that are having trouble. I thought it might be a firewall issue, but then it does not make sense that Firefox would work, and IE would not. So I thought maybe explorer might have some security feature that I could not find.

Thanks,
Mitch

PHP_Chimp

10:58 pm on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using any JavaScript on the form, or to generate the page that the form is on?
As NS vs. IE JavaScript is different, so it may be that some of the page is not working with IE.

Have you tested the page with IE? As depending on what code you have on the page there may also be issues with IE not actually following the standards and going off doing there own thing.

[edited by: PHP_Chimp at 11:00 pm (utc) on Dec. 21, 2007]

meatch

11:06 pm on Dec 21, 2007 (gmt 0)

10+ Year Member



Hey PHP_chimp,

Yah, that is the strange thing. It works in both IE and Firefox on my PC. Just not the client's. I am not using any javaScript to manage or validate the script, just php. I think I am just going to give the client ftp access, have them upload a series of images to the web, and then have a script target/manage those images. It seems easier than trying to work through their permission problems. It will also speed up the processing of the images for their gallery.

Thank you both for your time and support.
Mitch

Birdman

7:38 am on Dec 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It then seems redundant to use FTP to then transfer the file from the TMP directory to my destination folder.

Not really, when you consider the file ownership issue. If PHP wants to store the file, the directory will need to be chmod 777 or be owned by apache. Both can be bad.

If I upload the file with a form then use ftp(in the background) to save the file then it will have "normal" ownership(ie, by your normal user).

I think it's a decent solution to a problem that many people have come accross. I sure don't want my directories chmod 777 :)

Marty

P.S. I like to store http/PHP uploaded files in their own directory and go ahead and let apache own that directory(requires root access). Then I can keep permissions safe.

meatch

4:39 pm on Dec 22, 2007 (gmt 0)

10+ Year Member



Thanks Birdman,

You are absolutely right. That is a great way to control the privs–so that would be a great solution.

Mitch