1

When I use $filename below I can never store anything in the database. I've tried basename function but it doesn't seem to store anything.

 $filename = $_FILES['file']['name']; /* Location */ $location = "../media/images/profile-pics/".$filename; $uploadOk = 1; $imageFileType = pathinfo($location,PATHINFO_EXTENSION); /* Valid Extensions */ $valid_extensions = array("jpg","jpeg","png"); /* Check file extension */ if( !in_array(strtolower($imageFileType),$valid_extensions) ) { $uploadOk = 0; } if($uploadOk == 0){ echo 0; }else{ /* Upload file */ if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){ }else{ echo 0; } } //$filename = basename($_FILES['file']); removed, but still doesn't store file in db. $stmt = $db->prepare("UPDATE contacts SET name = ?, email = ?, phone = ?, jobtitle = ?, profile_pic = ? WHERE id = ?"); $stmt->bind_param("sssssi", $name, $email, $phone, $jobtitle, $filename, $id); $stmt->execute(); $stmt->close(); 

1 Answer 1

1

Just get rid of $filename = basename($_FILES['file']); - you've already populated $filename with $_FILES['file']['name'] up above, which is the correct way to access the filename of the file as it was uploaded.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I have removed it and it still doesn't store it.
Is it saving the file in the media/images/profile-pics/ directory with the right filename? Are other fields, name, email, etc. getting updated with the DB query? Have you attempted to echo out what the $filename variable is holding at various points in the script?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.