# Problems with php ftp uploader

**URL:** https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946
**Category:** programming
**Created:** [July 27, 2004, 9:43am UTC](https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946 "2004-07-27T09:43:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mid\_ori](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mid\_ori](https://forum.kirupa.com/u/mid_ori)
#### Post date: [July 27, 2004, 9:43am UTC](https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946/1 "2004-07-27T09:43:23Z")

</div>

Hi,

I’m currently trying to create a ftp uploader for the company website, so we can recieve artwork from clients, however it isn’t working can anyone look at the script and see where its going wrong. I’ve looked at loads of tutorials but it still wont work.

cheers

```php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<?php
$file_dir = "/public_html/ftp";
$file_url = "http://www.iceni.tv/ftp";

foreach( $HTTP_POST_FILES as $file_name => $file_array) {
	print "path: ".$file_array['tmp_name']."<br>
";
	print "name: ".$file_array['name']."<br>
";
	print "type: ".$file_array['type']."<br>
";
	print "size: ".$file_array['size']."<br>
";
	
	if (is_uploaded_file( $file_array['tmp_name'] )
	&& $file_array['type'] == "image/gif" ) {
	move_uploaded_file( $file_array['tmp_name'], "$file_dir/$file_name")
		or die ("couldn't copy");
	print "<img src=\"$file_url/$file_name\"><p>

";
	}
}
?>
<body>
<form encrpt="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<input type="file" name="fupload"><br>
<input type="submit" value="upload!">
</form>
</body>
</html>

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 3:42pm UTC](https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946/2 "2004-07-27T15:42:10Z")

</div>

Why using an array ?

try this… and see if it works

```php

 #simple test
  <?php
  $ftp_user_name ='';
  $ftp_user_pass ='';
  $ftp_server='';
  
   // open some file for reading
  $file = 'somefile.txt';
  $fp = fopen($file, 'r');
  
  // set up basic connection
  $conn_id = ftp_connect($ftp_server) 
 or die ("Ftp server connection failed:);
  
  // login with username and password
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) 
 or die ("user / password not correct");
  
  // try to upload $file
  if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
     echo "Successfully uploaded $file
";
  } else {
     echo "There was a problem while uploading $file
";
  }
  
  // close the connection and the file handler
  ftp_close($conn_id);
  fclose($fp);
  
  ?> 

```

```php

 #server 2 server ..
 <?php
 $FTP_HOST ="ftp.host.com"; 
 $FTP_USER ="user";
 $FTP_PW ="mypasswd";
 $FTP_ROOT_DIR="/";
 $LOCAL_SERVER_DIR = "images/";
 $FTP_DIR = "mydir/";
 $handle=opendir($LOCAL_SERVER_DIR);
 while (($file = readdir($handle))!==false)
 {
     if(!is_dir($file)){
 	    $f[]="$file";		
 	  }
 }
 closedir($handle);
 sort($f);
 $count=0;
 $mode = FTP_BINARY; // or FTP_ASCII
 $conn_id = ftp_connect($FTP_HOST); 
 if(ftp_login($conn_id, $FTP_USER, $FTP_PW)){
     print "from: ".$LOCAL_SERVER_DIR."<br>";
     print "to: ".$FTP_HOST.$FTP_ROOT_DIR.$FTP_DIR."<br>";
     ftp_pwd($conn_id);
     ftp_mkdir($conn_id,$FTP_DIR);
     ftp_chdir($conn_id,$FTP_DIR); 
     foreach($f as $files) {
 	    $from = fopen($LOCAL_SERVER_DIR.$files,"r");	 
 	    if(ftp_fput($conn_id, $files, $from, $mode)){
 		    $count +=1;
 		    print $files."<br>";
 	    }
     }
     ftp_quit($conn_id);
 }
 print "upload : $count files.";
 ?>
 

```

\</span\>\</span\>

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 29, 2004, 10:30am UTC](https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946/3 "2004-07-29T10:30:36Z")

</div>

yes those work i tried them

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 29, 2004, 4:07pm UTC](https://forum.kirupa.com/t/problems-with-php-ftp-uploader/58946/4 "2004-07-29T16:07:39Z")

</div>

well i can’t them to work, i’m not really what i’m doing to get them to work, how do i implement them to html form code i have? sorry i’m new to php and don’t get to use it often.
