Jason,
Thanks for your help.  The purpose of this script is to upload an image,
assign an image name based upon a record name received in a mysql query,
store the image name in the mysql table, and then ftp the file to a
directory on the server.
Thanks again,
Hugh

The following script is now working without error.
<?php
if (isset($asset_n))
 {
   if (isset($asset_n) and !isset($upload))
  {
  print "<h3>Input your digital photo.</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=photo2 value=$asset_n >";
  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";
  if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
   {
   $fp=fopen($HTTP_POST_FILES['userfile']['tmp_name'],"rb");
   $file_stream=fread($fp,300000);
   fclose($fp);

   $table="  ";
   $db="   ";
   $user="   ";
   $pass="  ";
   $link=mysql_connect("localhost","$user","$pass");
   if (! $link) die("Can't log in at this time");
   mysql_select_db($db,$link) or die ("Can't get database at this time");
   $query="update $table set photo2='".$photo2."' where
asset_n='".$asset_n."' ";
   $result=mysql_query($query);
   mysql_close($link);
   }
  call_user_func('ftp_transfer',$photo2,$file_stream);

  print "<a href=update.php?asset_n=$asset_n&edit=1>return to update
page</a>";
  }
 }
 // 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_close($conn_id);
 ftp_quit($conn_id);
 }
php?>
----- Original Message -----
From: "Hugh Danaher" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 27, 2003 1:16 PM
Subject: Re: [PHP] File Upload and ftp transfer problem


> Thanks Jason, I'll try that, and let you know the results.  Hugh
> ----- Original Message -----
> From: "Jason Wong" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, March 27, 2003 11:48 AM
> Subject: Re: [PHP] File Upload and ftp transfer problem
>
>
> > On Friday 28 March 2003 03:16, Hugh Danaher wrote:
> > > 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.
> >
> > It's doing exactly what you're telling it to do.
> >
> >   $file_stream=$HTTP_POST_FILES['userfile']['tmp_name'];
> >
> > This only contains the _name_ of the temporary file which contains the
> > contents of your uploaded file.
> >
> > What you need to do is send the _contents_ of the file pointed to by
> > $file_stream. Take a look at fread() and/or file().
> >
> > --
> > Jason Wong -> Gremlins Associates -> www.gremlins.biz
> > Open Source Software Systems Integrators
> > * Web Design & Hosting * Internet & Intranet Applications Development *
> > ------------------------------------------
> > Search the list archives before you post
> > http://marc.theaimsgroup.com/?l=php-general
> > ------------------------------------------
> > /*
> > I do not find in orthodox Christianity one redeeming feature.
> > - Thomas Jefferson
> > */
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to