$_FILES
$text = $_FILES;
$local = $text['file']['tmp_name'];
$name = trim(($text['file']['name']));
$name= strtolower($name);
$upl = move_uploaded_file($local, 'E:/OpenServer/domains/js/Part_1_JS/img/'.$name);
echo $name;
<form action="#" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input type="submit" value="submit" />
</form>
// Singleton для соединения с бд.
class ConnectDb {
private static $instance = null;
private $conn;
private $host = 'localhost';
private $user = 'kda';
private $pass = 'kda';
private $name = 'kda';
// The db connection is established in the private constructor.
private function __construct()
{
$this->conn = new PDO("mysql:host={$this->host};
dbname={$this->name}", $this->user,$this->pass,
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
}
public static function getInstance()
{
if(!self::$instance)
{
self::$instance = new ConnectDb();
}
return self::$instance;
}
public function getConnection()
{
return $this->conn;
}
}
//Применение.
$instance = ConnectDb::getInstance();
$conn = $instance->getConnection();
$conn = ConnectDb::getInstance()->getConnection();
foreach($conn->query('SELECT * from projects') as $row) {
echo $row['name']."\n";
}
<?php
class Singleton
{
private static
$instance = null;
/**
* @return Singleton
*/
public static function getInstance()
{
if (null === self::$instance)
{
self::$instance = new self();
}
return self::$instance;
}
private function __clone() {}
private function __construct() {}
}