PHP Classes

File: uploady/actions/delete_file.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   Uploady PHP Upload File to MySQL   uploady/actions/delete_file.php   Download  
File: uploady/actions/delete_file.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Uploady PHP Upload File to MySQL
Store file upload details in a MySQL database
Author: By
Last change: Fixea
Date: 2 months ago
Size: 1,361 bytes
 

Contents

Class file image Download
<?php

include_once '../session.php';

header("Content-type: application/json; charset=UTF-8");

$handler = new Uploady\Handler\UploadHandler($db);

if (isset(
$_POST['file_id']) && isset($_POST['user_id'])) {

   
$fileID = $utils->sanitize($_POST['file_id']);
   
$userID = $utils->sanitize($_POST['user_id']);

    if (
$handler->fileExist($fileID) && $handler->userExist($userID)) {
       
$file = json_decode($handler->getFile($fileID)->file_data);
        if (
$handler->deleteFile($fileID, $userID)) {
           
unlink(realpath("../" . UPLOAD_FOLDER . "/{$userID}/{$file->filename}"));
           
http_response_code(200);
            echo
json_encode([
               
"status" => "success",
               
"message" => $lang["general"]['file_deleted_success']
            ]);
        } else {
           
http_response_code(400);
            echo
json_encode([
               
"status" => "error",
               
"message" => $lang["general"]['file_deleted_failed'] . " ):"
           
]);
        }
    } else {
       
http_response_code(400);
        echo
json_encode([
           
"status" => "error",
           
"message" => $lang["general"]["file_or_user_not_found"]
        ]);
    }
} else {
   
http_response_code(400);
    echo
json_encode([
       
"status" => "error",
       
"message" => $lang["general"]['file_id_missing']
    ]);
}