Похожие чаты

<?Php Class Photo extends Db_object { //Properties

//Abstract Tables
protected static $db_table = "photos";
protected static $db_table_fields = ['photo_id','title','description','filename','type','size']; // Column from database

public $photo_id ;
public $title ;
public $description;
public $filename;
public $type;
public $size;

//Setting properties Array

public $tmp_path;
public $upload_directory = "images";
public $custom_errors = [];
public $upload_errors_array = [

//Associative Arrays
UPLOAD_ERR_OK => "There is no error, the file uploaded with success",
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini. ",
UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded. ",
UPLOAD_ERR_NO_FILE => "No file was uploaded. ",
UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder. Introduced in PHP 5.0.3. ",
UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk. Introduced in PHP 5.1.0. ",
UPLOAD_ERR_EXTENSION => "A PHP extension stopped the file upload.",

];


//Set File Method
//This is passing $_FILES['uploaded_file'] as Argument

public function set_file($file){

//Error Check
if (empty($file) || !$file || !is_array($file) ){
$this->custom_errors[] = "There was no files uploaded here";
return false;

}elseif ($file['error'] !=0) { //check if a file is uploaded
//saving inside erors array
$this->custom_errors[] = $this->upload_errors_array[$file['error']];
return false;

} else{


//Assign a key
$this->filename = basename($file['name']);
$this->tmp_path = $file['tmp_name'];
$this->type = $file['type'];
$this->size = $file['size'];
}


}

public function picture_path() {

return $this->upload_directory.DS.$this->filename;
}

public function save(){

//Error Checking

if($this->photo_id){
$this->update();
}else {

if (!empty($this->custom_errors)) {
return false;
}
//Check if the filename is empty
if (empty($this->filename) || empty($this->tmp_path)){
$this->custom_errors[] = "The file was not available";
return false;
}

//target path.permanent location of file
$target_path = SITE_ROOT .DS . 'admin' . DS . $this->upload_directory . DS .$this->filename;
$this->create();


if (file_exists($target_path )) {
$this->custom_errors[] = "This file {$this->filename} already exists";
return false;

}
//Move the file

if (move_uploaded_file($this->tmp_path, $target_path)){
if ($this->create()){
//take the temp out
unset($this->tmp_path);
return true;
}
}else {
//Permission
$this->custom_errors[] = "The file directory probably does not have permission";
return false;
}
}

}
}

1 ответов

15 просмотров

Please format the code you posted, by wrapping it in triple backticks. -> `

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта