DamiToma
DamiToma

Reputation: 1106

HTML & PHP - Not displaying updated image

I'm working on a login service with avatar. I'm also working on a crop-service that should let me crop the photo and then set it as my account's avatar. A just have a form width a file input tag and a submit button. When I click on the "submit" input, the crop window opens and show me the avatar to crop. This is my PHP and HTML code.

<html>
<body>
<form method="post">
<input type="file" name="image">
<input type="submit" name="submit">
</form>
</body>
</html>

<?php 
if(isset($_POST["submit"])) {
move_uploaded_file($_FILES["image"]["tmp_name"],"photos/");
}
?>

The problem is when I've already created an avatar and I want to update it. When I upload the image and set it as avatar, the crop window is not showing me the new image, but the old one.

What am I doing wrong? Thanks!

Upvotes: 0

Views: 1183

Answers (2)

Striezel
Striezel

Reputation: 3758

The problem is when I've already created an avatar and I want to update it. When I upload the image and set it as avatar, the crop window is not showing me the new image, but the old one.

I'm not sure whether this is an issue with your code (not enough code shown here) or an issue with your browser (no information about that either). However, many browser cache images locally. That is, even if you updated the image successfully on the server, it may not show up immediately in the browser on the client side - because the browser is still using the locally cached version. Reload the web page without using the browsers cache to rule out that possibility. This can be done with Ctrl+F5 in browsers like Firefox, other browsers provide similar shortcuts.

Upvotes: 1

reza
reza

Reputation: 1507

first you have to set enctype attribute as multipart/form-data

<form method="post" action="index.php" enctype="multipart/form-data">

and second of all move_uploaded_file() function needs file name not a directory as a parameter.

move_uploaded_file($_FILES["image"]["tmp_name"],"photos/avatar.jpg");

Upvotes: 1

Related Questions