Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.         session_start();
  3.         if (!isset($_SESSION['username']))
  4.         header("location:login.php");
  5.  
  6.         $localfile = pathinfo($_FILES['image']['name']);
  7.         $type = explode("/", $_FILES['image']['type'], 2);
  8.  
  9.         $connect = ftp_connect("ftp.engammalsko.frihost.org");
  10.         ftp_login($connect, "engammal", "******");
  11.  
  12.  
  13.         ftp_chdir($connect, "public_html/lss/images/members");
  14.         $list = ftp_nlist($connect, ".");
  15.  
  16.         foreach ($list as $file)
  17.         {
  18.                 if(preg_match("/{$_SESSION['username']}/", $file))
  19.                 ftp_delete($connect, $file);
  20.         }
  21.  
  22.         if ($type['0'] == "image")
  23.         ftp_put($connect, "{$_SESSION['username']}.{$localfile['extension']}", $_FILES['image']['tmp_name'], FTP_BINARY);
  24.         ftp_close($connect);
  25.  
  26.         $mysqli = new mysqli("localhost", "engammal", "******", "engammal_lss");
  27.         if ($type['0'] == "image")
  28.         $query=$mysqli->query("UPDATE members SET img = '{$_SESSION['username']}.{$localfile['extension']}' WHERE username = '{$_SESSION['username']}'");
  29.         header("Location: avatar.php");
  30. ?>