I'm trying to get the following script to ftp transfer an uploaded image file so as to 
get around a file permission problem.  The upload portion of this works without 
problem, the ftp portion doesn't spit out any errors either, but the file transfered 
is just the name of the uploaded temp file and not the file itself.  
If I do a filesize() on $file_stream, I get 44K (the size of the image uploaded), I 
then transfer this var to the ftp function but what gets ftp and saved as a file is 
only 14 bytes.  The saved file has "/tmp/phpDcJSOq" as its entire contents. 
The upload scrip is below.
Thanks for any help to resolve this problem.
Hugh
 
<?php
if (isset($asset_n))
 {
 if (isset($asset_n) and !isset($upload))
  {
  print "<h3>Input your digital photo of the specimen.</h3>";

  print "<form enctype=\"multipart/form-data\" action=$PHP_SELF method=post>";
  print "<input type=hidden name=MAX_FILE_SIZE value=300000>";
  print "Send this tree picture: <br><input name=userfile type=file>";
  print "<input type=hidden name=upload value=1 >";
  print "<input type=hidden name=asset_n value=$asset_n>";
  print "<input type=submit value=\" Upload File \">";
  print "</form>";
  }
 if ($upload==1)
  {
  $photo2="L".(100*$asset_n).".jpg";
  // move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], 
"./directory/".$photo2.""); // doesn't work because of file permissions.
  $file_stream=$HTTP_POST_FILES['userfile']['tmp_name'];
   
  if ($upload==1)
   {
   call_user_func('ftp_transfer',$photo2, $file_stream);
   header("location: update.php?asset_n=$asset_n&edit=1");
  }
 }

 // functions
 // set up basic ftp connection
function ftp_transfer($photo2,$file_stream)
 {
 $ftp_server="   ";
 $ftp_user_name="   ";
 $ftp_user_pass="   ";
  
 $conn_id = ftp_connect($ftp_server); 

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

 // check connection
 if ((!$conn_id) || (!$login_result)) 
  { 
  print "FTP connection has failed!<br>";
  print "Attempted to connect to $ftp_server <br>"; 
  exit; 
  } 
 // upload the file
 $fp = tmpfile(); 
 fwrite($fp, $file_stream); 
 rewind($fp); 

 $destination_file="./directory/".$photo2;
 $upload = ftp_fput($conn_id, $destination_file, $fp, FTP_BINARY); 
 // check upload status
 if (!$upload) 
  { 
  print "FTP upload has failed!<br>";
  } 
 // close the FTP stream 
 ftp_quit($conn_id);
 }
php?>

Reply via email to