Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have an upload feature which has a delete feature on this.

See below my deleteProfile code which runs on MyProfile, once i select delete file it redirects to a blank page under 'deleteProfile.php' whereas I want it to stay on MyProfile.php

can someone help?

What I have tried:

<?php
session_start();
include("dbConnect.php"); 
 header("Location:myProfile.php")
$sessionid = $_SESSION['currentUserID'];

$filename = "uploads/profile".$sessionid. "*";
$fileinfo = glob($filename); //all files matches the search above
//Where we want to explode and which string we want to explode
$fileext = explode(".", $fileinfo[0]); // first result from array from glob search
$fileactualext = $fileext[1]; // e.g actual ext equal to for example jpeg

$file = "uploads/profile".$sessionid. ".". $fileactualext;

//delete file 
if (!unlink($file)){
	echo "File was not deleted";
}else{
	echo "file was deleted!";
}
$stmt = $conn->prepare("UPDATE Profile SET ProfilePicture='{$fileNameNew}' WHERE UserID='{$sessionid}'");
 $stmt->execute();

echo "<img src='uploads/default-profile.jpg' width='150' height='150'/>";
 header("Location:myProfile.php?deletesuccess=1")
?>
Posted
Updated 30-Jan-18 4:50am
Comments
Mohibur Rashid 28-Jan-18 16:56pm    
Can your application leave line 4? header?

1 solution

You cannot redirect with header(location) after have begin writing the buffer with echo.
And line 4, like Rashid said, there is another mistake, you send php in another file, and so it never execute line 5 and all the next.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900