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)) { unlink($target_png1); } if (file_exists($target_jpg1)) { unlink($target_jpg1); } if (file_exists($target_jpeg1)) { unlink($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?

Category:php Views:76 Time:2019-03-15
Tags: php file

Related post

  • Django best practices replacing old files with file uploads 2011-01-27

    In summary, what I'm trying to accomplish here is: To perform transformation over uploaded files' names for organization and security's sake Not to keep old files in storage forever Let's say that you have a Company model which has a logo. Something

  • Uploading ftp: file reverts to old one? 2011-04-23

    What does it mean when you upload a file to your ftp server using sftp and the server automatically reverts the file to an older version? I was wondering what was going on. The file I am transferring is verified as the one I want. I've tried deleting

  • How to prevent paperclip gem from deleting old files when new files are uploaded? 2012-03-30

    An app uses paperclip to handle file uploads for user avatars. Paperclip currently deletes old files when new ones are files, however, I wish for the users to see a history of what they have uploaded. Is there a way to prevent paperclip from deleting

  • Uploading old pst files to skydrive account 2014-10-25

    Just migrated form xp to windows 7 and installed office 2013. Key challenge is that I am trying to accomplish 2 things: 1) be able to access mail from 3rd party mailboxes, and have this data sync'd with my PC, Surface tablet, and windows 8 laptop, an

  • What's the most bullet-proof way to upload large files in a web app? 2008-11-25

    We have to accept large file uploads (video content) and want to do that in a way that works well across all standards-compliant browsers and plug-ins. Our current setup looks like this: SWFUpload input type="file" for graceful degradation On the ser

  • How do I upload a file from a dynamically created FileUpload control with ASP.NET? 2008-12-17

    In my code attached below, I'm trying to upload a file via ASP.NET. I am dynamically creating the FileUpload control so that means it's not in my ViewState which (I think) means I can't use the control for uploading files unless I use the old fashion

  • Upload a file AJAX-ically using Wicket 2009-08-04

    I want to upload a file with AJAX in Wicket. It seems to me that Wicket does not support this feature. Is it possible? --------------Solutions------------- Check out the source code from the Wicket Examples for upload:

  • How to upload multiple files in jsp? 2009-09-16

    I have been using "input type='file' " tag to upload single file but I want to extend the functionality to upload multiple files (selecting multiple file in the same dialog box to upload). I don't have any idea how to accomplish these, any ideas and

  • Codeigniter multiple file upload messes file extension 2009-12-15

    I am trying to get a multiple upload library working for my Codeigniter based website. I have it working almost but I have a slight problem if I upload more than one image, the file extentions get screwed up; for example, if I upload three JPEGS, I g

  • Uploading a file using PHP 2010-06-24

    I am uploading a file to from my own server with using an API in PHP: if (isset($mime)) { $tmp_file = $tmp_path . $_FILES['file']['name']; // Store the track temporary. if (move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file)) {

  • Can we upload a file size of 500MB using WCF Service? 2010-06-29

    I have written a WCF Service to upload a file. So far i am able to upload a file size of 300MB. When i tried further i am receiving an error mentioning "The underlying connection was closed: The connection was closed unexpectedly." I have increased t

  • Getting Request timed out error when uploading large files 2010-10-06

    We have page that allows the users to upload documents (multiple). When the upload takes a long time - either due to the size of the files or due to slow upload speeds - we get a exception saying "Request timed out". We found that the exception is th

  • How do I upload a file with metadata using a REST web service? 2010-10-15

    I have a REST web service that currently exposes this URL: http://server/data/media where users can POST the following JSON: { "Name": "Test", "Latitude": 12.59817, "Longitude": 52.12873 } in order to create a new Media metadata. Now I need the abili

  • Upload a file and destory it after session is completed 2011-03-04

    I want to upload a file through mvc and delete the file after the session is destroyed ? --------------Solutions------------- Check out this link which has code in c#. This will tell you how to find a file and delete it, but you must handle c

  • Ruby on Rails: Server error with while trying to upload a file using attachment_fu: (can't convert nil into Integer) 2011-03-17

    I followed a simple example to upload a file (see link to code below). When i add to the upload form the field <%= f.file_field :uploaded_data %>, and click submit button on the form (with or without a a file attachment), i get an error message

  • django ImageField - how to customise name + remove old file 2011-03-18

    I have a model with an ImageField in it. I've already set the upload_to and created my own FileSystemStorage class to deal with saving the file with a unique name... however... This setup allows me to upload and save a file with a unique name for eac

  • How do I upload some file into Azure blob storage without writing my own program? 2011-07-05

    I created an Azure Storage account. I have a 400 megabytes .zip file that I want to put into blob storage for later use. How can I do that without writing code? Is there some interface for that? --------------Solutions------------- Free tools: Visual

  • How to upload a file to a .NET 3.5 WCF service hosted in IIS? 2011-08-04

    I've been ripping my hair out for a while now. Can someone provide a really simple example (or a link to a working example) of how to upload a file to a WCF service hosted in IIS. I've started with something simple. I want to call a URL from a client

  • How to upload a file to the server using Yesod 2011-09-18

    I'm trying to write a form that allows users to upload a file to my server. I saw Yesod uses fileAFormReq for such a functionality but was unable to get it to work, running into compilation errors, the latest of which was: "No instance for (RenderMes

  • css is not working after uploading the file on server with filezilla or cpanel 2011-09-19

    I have uploaded the file.css file on server with filezilla and also with cpanel. But when i browse the website the css has no impact. I changed: padding-left: 10px; If i see the Page view source i see that the older file is there. What can be the rea

  • Can't upload 5mb file using AJAX file uploader 2011-09-21

    I am using the file uploader plugin (from: to upload files to my website. If you are using a moden web browser (like Firefox 6 or Chrome 13), then it uploads by streaming the file in the POST body, and can giv

  • SharePoint 2010,SandBox Solution,uploaded .STP files to _catalogs/lt using Feature not coming in GetCustomListTemplates 2011-10-03

    I have sandbox solution which has 2 features (both are sitecollection level features) I am activating both feature using same USER. feature 1 : that uploads .stp files to _catalogs/lt folder via module file feature 2 (is dependent on feature 1) : it

  • Upload Multiple Files In PHP 2012-01-28

    I wonder whether someone may be able to help me please. Using some excellent online tutorials I've put together the code below which allows a user to upload image files to a server folder and the filename and other details to a mySQL database. PHP Sc

  • Error 413 when uploading large files using WCF Service on IIS7` 2012-03-12

    I have a web application which enables users to upload files. The files are then saved using a WCF service on another service. This uploading works fine until I upload a file around 4.5 MB. When I upload a file above a certain size, I get the error:

  • How to upload a file with a different file name 2012-04-14

    I have a file input known as 'name=fileImage'. Now I have php code below where it checks to see if file exists in the folder (ImageFiles) or not: if (file_exists("ImageFiles/" . $_FILES["fileImage"]["name"])) { } My question is that if a file does ex

Copyright (C), All Rights Reserved.

processed in 0.120 (s). 11 q(s)