Jump to content

php ftp_put error


TecBrat

Recommended Posts

I am attempting to put two scripts together, one that I wrote to upload files using move_uploaded_file, but I couldn't manage them with ftp because they belonged to apache "nobody" So I am attempting to replace that move... with code I found elsewhere. I was sucessful in a simplified version, but I seem to have broken it when I got more complex. Will someone please take a look at my code and see if you recoganize my error? if you want to see my working, simplified, version, let me know.

<form method="POST" enctype="multipart/form-data" action=<? echo($PHP_SELF);?>>
    <input type=hidden name=company_name value="test_company">
    <input type="file" name="file_name" size="20">
    <input type="submit" value="Submit" name="B1">
</form>


<? if(!$B1==""){

$company_name=strtolower($company_name);
$ex_pattern = '/[^a-zA-Z0-9]/';
$newdir=preg_replace($ex_pattern,'_',$company_name);
$path='/home/username/public_html/mytestdir/';
echo("<br>Company Name: $company_name<br>New Dir: $newdir<br>Path: $path");

if(!is_dir($path.$newdir))
  {
  mkdir($path.$newdir);
  echo("<br>creating $path$newdir<br><br>");
  }


$conn = ftp_connect("localhost");
echo("$conn<br>");
if (ftp_login ( $conn, 'username', 'password')) {echo("Connected<br>");
}else{
echo("Error<br>");}

//$myName = $_POST['name']; //This will copy the text into a variable
   $myFile = $_FILES['file_name']; // This will make an array out of the file information that was stored.
   $nameforfile=$myFile['name'];

       $destination_path = '../public_html/mytestdir/'.$newdir.'/';
       echo("Destination Path: $destination_path<br>");
//where you want to throw the file on the webserver (relative to your login dir)
$dt=date(Ymd);
   $destination_file = $destination_path.$dt.'_'.$nameforfile;

//This will create a full path with the file on the end for you to  use, I like splitting the variables like this in case I need to use on on their own or if I`m dynamically creating new folders.

       $file = $myFile['tmp_name'];

//Converts the array into a new string containing the path name on the server where your file is.

   $upload = ftp_put($conn, $destination_file, $file, FTP_BINARY);// upload the file
   if (!$upload) {// check upload status
       echo "FTP upload of $destination_file has failed!";
   } else {
       echo "Uploaded $file to $conn as $destination_file";
   }
}
?>

 

here's my output when uploading a file called TYRE_PR.jpg

Company Name: test_company
New Dir: test_company
Path: /home/username/public_html/mytestdir/
creating /home/username/public_html/mytestdir/test_company

Resource id #2
Connected
Destination Path: ../public_html/mytestdir/test_company/

Warning: ftp_put() [function.ftp-put]: Rename/move failure: No such file or directory in /home/username/public_html/ftp.php on line 46
FTP upload of ../public_html/mytestdir/test_company/20070305_TYRE_PR.jpg has failed!

Link to comment
https://forums.phpfreaks.com/topic/41316-php-ftp_put-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.