다음 스크립트의 목적은 제공된 "id"를 사용하여 annonces 테이블에서 항목을 삭제하는 것입니다.PHP/PDO : 서버에서 이미지 삭제
나는 또한 같은 다음 폴더에 저장되어있는 이름 $ imageAnnonce의 파일 삭제합니다 :/업로드
을 내가 할 수있는 방법이 PHP를 사용하고 계십니까? 따라서 귀하의 경우
unlink(pathtofile);
:
<?php
$PARAM_hote='aaaaaaaa';
$PARAM_port='3306';
$PARAM_nom_bd='bbbbbbbbbbb';
$PARAM_utilisateur='cccccccccccc';
$PARAM_mot_passe='ddddddddddddd';
// Create connexion to BDD
$connexion = new PDO('mysql:host='.$PARAM_hote.';port='.$PARAM_port.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
try {
// GET POST DATA
$idAnnonce = $_POST['idAnnonce'];
$imageAnnonce = $_POST['imageAnnonce'];
// PREPARE DELETE ON TABLE
$sqlInsert = "DELETE FROM annonces WHERE id=:idAnnonce ";
$resultats = $connexion->prepare($sqlInsert);
$resultats->bindValue(':idAnnonce', $idAnnonce, PDO::PARAM_INT);
$resultats->execute();
// Now, i would like to delete image with name = $imageAnnonce in the folder /uploads
// ... ??
// How many row have been impacted ?
echo $resultats->rowCount();
} catch(Exception $e) {
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
?>
[PHP 파일을 삭제] (https://www.google.com/search?q=php+delete+file) – moonwave99