Not sure if this belongs here...

I'm building a site with a simple file upload feature... worked yesterday, but now all of a sudden my browser is not interpreting the PHP code at all... The code being used is straight from the php.net manual examples. I'm stumped...

This is my code...

<?php
  if(isset($_POST['SubmitFile'])){
     $myFile = $_FILES['txt_file']; // This will make an array out of the file information that was stored.
     $file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is.

 $myFileName = basename($_POST['txt_fileName']); //Retrieve filename out of file path

 $destination_file = "/".$myFileName;  //where you want to throw the file on the webserver (relative to your login dir)

 $conn_id = ftp_connect($ftp_server);        // set up basic connection
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h2>You do not have access to this ftp server!</h2>");  // login with username and password, or give invalid user message
 if ((!$conn_id) || (!$login_result)) {  // check connection
         // wont ever hit this, b/c of the die call on ftp_login
         echo "FTP connection has failed! <br />";
         echo "Attempted to connect to $ftp_server for user $ftp_user_name";
         exit;
     } else {
     //    echo "Connected to $ftp_server, for user $ftp_user_name <br />";
 }

 $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
 if (!$upload) {  // check upload status
     echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
 } else {
     echo "Uploading $myFileName Complete!<br /><br />";
 }

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

<html>
  <head>

  </head>
  <body>
       <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">

       Please choose a file: <input name="txt_file" type="file" id="txt_file" tabindex="1" size="35" onChange="txt_fileName.value=txt_file.value" />
       <input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />

       <input type="submit" name="SubmitFile" value="Upload File" accesskey="ENTER" tabindex="2" />
 </form>
  </body>
<html>

This is called after the user has logged in properly, and it shows this...

<?php
  if(isset($_POST['SubmitFile'])){
     $myFile = $_FILES['txt_file']; // This will make an array out of the file information that was stored.
     $file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is.

 $myFileName = basename($_POST['txt_fileName']); //Retrieve filename out of file path

 $destination_file = "/".$myFileName;  //where you want to throw the file on the webserver (relative to your login dir)

 // connection settings
 $ftp_server = "208.97.108.2";  //address of ftp server.
 $ftp_user_name = "photovisions"; // Username
 $ftp_user_pass = "photovisions1";  // Password

 $conn_id = ftp_connect($ftp_server);        // set up basic connection
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h2>You do not have access to this ftp server!</h2>");  // login with username and password, or give invalid user message
 if ((!$conn_id) || (!$login_result)) {  // check connection
         // wont ever hit this, b/c of the die call on ftp_login
         echo "FTP connection has failed! <br />";
         echo "Attempted to connect to $ftp_server for user $ftp_user_name";
         exit;
     } else {
     //    echo "Connected to $ftp_server, for user $ftp_user_name <br />";
 }

 $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
 if (!$upload) {  // check upload status
     echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
 } else {
     echo "Uploading $myFileName Complete!<br /><br />";
 }

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

<html>
  <head>

  </head>
  <body>
       <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">

       Please choose a file: <input name="txt_file" type="file" id="txt_file" tabindex="1" size="35" onChange="txt_fileName.value=txt_file.value" />
       <input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />

       <input type="submit" name="SubmitFile" value="Upload File" accesskey="ENTER" tabindex="2" />
 </form>
  </body>
<html>

I can't figure out why this page, and only this page, isn't hiding the PHP. Any thoughts?

    What's the file extension of this script? Can you give us a direct link to this page?

      Write a Reply...