php - Removing image from server -


i trying remove records database uploaded image record server.i have function in controller.

public function delete(request $request)     {         if($request->ajax())         {             $id=$request->get('id');             if($id)             {                 $delete=category::where('id',$id)->first();                 $delete->delete();                 $imgfile='c:\xampp\htdocs\larapro\public\newuploads\<?php echo $delete->image;?>';                 unlink($imgfile);                 echo json_encode(true);die;             }         }         echo json_encode(false);die;     } 

unlink(c:\xampp\htdocs\larapro\public\newuploads\<?php echo $delete->image;?>): result large

if use

$imgfile="c:\xampp\htdocs\larapro\public\newuploads\{$delete->image}"; 

it displays:

unlink(c: mpp\htdocs\larapro\public\ ewuploads{1470667358.png}): invalid argument

and wondering why x , n in link missing.

use slash (/) instead of backslash () in case:

$imgfile="c:/xampp/htdocs/larapro/public/newuploads/{$delete->image}"; 

or escape escape character like,

$imgfile="c:\\xampp\htdocs\larapro\public\newuploads\{$delete->image}"; 

and words x , n missing because \x , \n escape , new line character respectively.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -