0

Hello

Lets say I have a text file, in a local or remote location. I want to select it with a file picker (standard Windows browser seleccion). Once I have that selected, I want to click a send button. This send will download the text file from whereever it is at then FTP it over to a server. After that, I want to call a web service.

Lets start from scratch. What is the best way to do the selecting the file from anywhere? From anywhere I mean a Windows shared computer but it should be able to get from another FTP location.

Thank you

Edited by pritaeas: Moved.

2
Contributors
46
Replies
81
Views
4 Years
Discussion Span
Last Post by pritaeas
0

Cant seem to get your standard textbox and a button aside that says "Browse" working....

0

The standard HTML file input control will let you select from the computer it's on, and attached network computers, but NOT from FTP. I haven't come across any file pickers yet that support this, probably because it cannot be done without server-side scripting. Javascript only supports HTTP and now WebSockets.

0

OK got something semiworking......

(Itll do for now from the computer its on and attached network computers)

HTML:

<form id="form1input" action="page.php" method="post" enctype="multipart/form-data">
    <h3>File:</h3>
    <input id="file" type="file" name="file" /><br/>
    <input id="submit" type="submit" value="Upload File"/>
    </form>

PHP:

<?php



                $name=$_POST["file"];
                echo ($name);

                echo ($_POST["file"]);
                exit;

Says undefinded index file.....

0

Check the PHP forum, there are enough threads about uploading files.

I perfer doing this with jQuery or something...

0

Did you search this forum (PHP) ?

Yes. Maybe the terms I used were not correct/valid so thats why it didnt show me any valid solution.

0

Sorry, my bad.

No problem. Now we are getting somewhere :)

<?php
                print_r($_FILES);
                exit;

This is the result:

Array ( [file] => Array ( [name] => filetest.txt [type] => text/plain [tmp_name] => C:\xampp\tmp\phpCB31.tmp [error] => 0 [size] => 267 ) )

OK, thats one part. Now how do I continue on to FTP that over?

Example code Ive thought up now:

$thefile=$_FILES['name'];
$conn_id = ftp_connect("127.0.0.1"); //example IP
$login_result = ftp_login($conn_id, "username","password"); 
ftp_pasv($conn_id, true); 
$fp = fopen(getcwd()."/".$thefile.".txt", "w");
/*HERE I THINK IT WOULD HAVE TO MAKE A COPY OF THE FILE WITH THE CONTENTS*/
fclose($fp);
$upload = ftp_put($conn_id, $thefile.".txt", getcwd()."/".$thefile.".txt", FTP_ASCII); 

This Ive thought up basing myself on some examples on the net. Anything wrong or different I should do???

0

You need to use move_uploaded_file first I think, to move the file from the temp directory to a permanent location (during your upload). If it is successful, then delete it.

Am not sure what kind of files you are ftp-ing, but I'd consider FTP_BINARY.

0

You need to use move_uploaded_file first I think, to move the file from the temp directory to a permanent location (during your upload). If it is successful, then delete it.

Doesnt ftp_put do this?

Am not sure what kind of files you are ftp-ing, but I'd consider FTP_BINARY.

Only text nonunicode files

0
<?php



                $name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                $fp = fopen(getcwd()."/".$name.".txt", "w");

                /*I THINK I NEED SOMETHING HERE DIFFERENT THAN THE CODE IVE SEEN*/

                fclose($fp);

                $upload = ftp_put($conn_id, $name.".txt", getcwd()."/".$name.".txt", FTP_ASCII); 


                exit;

Hmmm cant quite get it...

0

The uploaded file is not in your getcwd() folder, but in sys_get_tmp_dir().

That's why I mentioned move_uploaded_file earlier, to move it from the temp folder to another location, prior to uploading.

Edited by pritaeas

0
$name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                $fp = fopen(getcwd()."/".$name, "w");


                echo ("hi");
                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

This code "works" but the location where I FTP the file TO is empty. There is no text content.

Im not sure if move_uploaded_file has anything to do with it.

0

Like I said, the current work directory is NOT where uploaded files are stored (unless you changed your PHP.INI).

Edited by pritaeas

0
<?php



                $name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                move_uploaded_file($name,getcwd()."/".$name);

                $fp = fopen(getcwd()."/".$name, "w");


                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

Is this what you ment or did I understand you incorrectly? (Doenst work)

0
<?php



                $name=$_FILES['file']['name'];


                print_r($_FILES);





                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 





                move_uploaded_file($_FILES["file"]["tmp_name"],getcwd()."/".$name);

                $fp = fopen(getcwd()."/".$name, "w");


                echo ("hi");
                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

Problably missing something obvious :(

0

I suggest you do some error checking to see what exactly fails. Is the uploaded file in your current work directory? Does ftp_connect return a resource, do ftp_login and ftp_put return true?

0

I suggest you do some error checking to see what exactly fails. Is the uploaded file in your current work directory? Does ftp_connect return a resource, do ftp_login and ftp_put return true?

Yup, Ill have to work if it returns true or false because there is no error message...

Ill do some if statements to print out...

0
if (move_uploaded_file($_FILES["file"]["tmp_name"],getcwd()."/".$name))
                    {
                        echo ("work");


                    }
                    else
                    {
                        echo ("doesnt work");
                    }

Changed to this and it prints out work but now it says:

Warning: ftp_put() [function.ftp-put]: Could not create file. in C:\testing\page.php on line 43

Hmm....FTP server is correct AFAIK.

Edited by riahc3

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.