lundi 29 juin 2015

move_upload_file uploading old file?

I'm working on an "Edit post" page which allows users to upload a picture to replace their old picture (displayed at the bottom of the post). Here's the code:

if (isset($_FILES['pic']['tmp_name']) && $_FILES['pic']['name']!=NULL) {

            $target_file1 = $dir . $postid . "." . $imageFileType1;
            $target_png1 = $dir . $postid . ".png";
            $target_jpg1 = $dir . $postid . ".jpg";
            $target_jpeg1 = $dir . $postid . ".jpeg";

            if (file_exists($target_png1)) {
            if (file_exists($target_jpg1)) {
            if (file_exists($target_jpeg1)) {
            move_uploaded_file($_FILES["pic"]["tmp_name"], $target_file1);

Through doing testing, I know that it works fine as long as the new picture is a different extension from the original. But if it's the same extension it deletes the old one and the move_uploaded_file reuploads the old one.

I know this because I commented out the "move_uploaded_files" and it successfully deleted the old file.

Any clues why it would be reuploading the old file instead of the uploaded one?

Aucun commentaire:

Enregistrer un commentaire