PHP FTP QUESTION

This is a discussion on PHP FTP QUESTION within the PHP General forums, part of the PHP Programming Forums category; Hello all. I'm a newbie at this and cannot figure out why the $source_file will not carry over from ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-19-2006
baustin75@gmail.com
 
Posts: n/a
Default PHP FTP QUESTION

Hello all. I'm a newbie at this and cannot figure out why the
$source_file will not carry over from the html page. I am geting this
error.

Notice: Undefined variable: source_file in c:\dev\handle_ftp.php on
line 30
FTP upload has failed!

-Any help or suggestions I would greatly appreciate!!!

------------------------------------------------
this is the html page


<html>

<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4
bgcolor=white vlink="#0000ff" link="#0000ff">

<form name="Attachments" method=POST action="handle_ftp.php"
enctype="multipart/form-data">

<input type=hidden name=box value="">

<tr>
<td nowrap width="1%">&nbsp;&nbsp;<b>Image:</b></td>
<td colspan=2>
<input type=file name=source_file size=20> <br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

</td>
</tr>
<input type=submit name=btnSubmit value=Submit size=20 style="border:
1px solid #0000FF">
</form>
</body>
</html>
------------------------------------------------------------
this is the php handling code

<?php

$ftp_server = "xxx";
$ftp_user_name = "xxx";
$ftp_user_pass = "xxx";


//puts file in current directory
//$destination_file=ftp_pwd($conn_id);

// set up basic connection
$conn_id = ftp_connect($ftp_server);

//var_dump($source_file);
//exit;

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user
$ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file,
FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as
$destination_file";
}

// close the FTP stream
ftp_close($conn_id);
?>

Reply With Quote
  #2 (permalink)  
Old 12-20-2006
Sean
 
Posts: n/a
Default Re: PHP FTP QUESTION


<baustin75@gmail.com> wrote in message
news:1166537391.573311.265040@79g2000cws.googlegro ups.com...
> Hello all. I'm a newbie at this and cannot figure out why the
> $source_file will not carry over from the html page. I am geting this
> error.
>
> Notice: Undefined variable: source_file in c:\dev\handle_ftp.php on
> line 30
> FTP upload has failed!
>
> -Any help or suggestions I would greatly appreciate!!!
>
> ------------------------------------------------
> this is the html page
>
>
> <html>
>
> <body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4
> bgcolor=white vlink="#0000ff" link="#0000ff">
>
> <form name="Attachments" method=POST action="handle_ftp.php"
> enctype="multipart/form-data">
>
> <input type=hidden name=box value="">
>
> <tr>
> <td nowrap width="1%">&nbsp;&nbsp;<b>Image:</b></td>
> <td colspan=2>
> <input type=file name=source_file size=20> <br>
>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>
> </td>
> </tr>
> <input type=submit name=btnSubmit value=Submit size=20 style="border:
> 1px solid #0000FF">
> </form>
> </body>
> </html>
> ------------------------------------------------------------
> this is the php handling code
>
> <?php
>
> $ftp_server = "xxx";
> $ftp_user_name = "xxx";
> $ftp_user_pass = "xxx";
>
>
> //puts file in current directory
> //$destination_file=ftp_pwd($conn_id);
>
> // set up basic connection
> $conn_id = ftp_connect($ftp_server);
>
> //var_dump($source_file);
> //exit;
>
> // login with username and password
> $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
>
> // check connection
> if ((!$conn_id) || (!$login_result)) {
> echo "FTP connection has failed!";
> echo "Attempted to connect to $ftp_server for user
> $ftp_user_name";
> exit;
> } else {
> echo "Connected to $ftp_server, for user $ftp_user_name";
> }
>


$source_file = $_POST['source_file'];

> // upload the file
> $upload = ftp_put($conn_id, $destination_file, $source_file,
> FTP_BINARY);
>
> // check upload status
> if (!$upload) {
> echo "FTP upload has failed!";
> } else {
> echo "Uploaded $source_file to $ftp_server as
> $destination_file";
> }
>
> // close the FTP stream
> ftp_close($conn_id);
> ?>
>




Add

$source_file = $_POST['source_file'];

Where I have indicated and that should sort it for you.

The problem is that you haven't transferred the values from the form to the
variable in your PHP.

Sean



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0