kat01 Posted December 11, 2009 Share Posted December 11, 2009 Hi, I'm doing uploading files site and I need it to ask from a user yes or no if file exists. How would I do this? if (file_exists($uploadfile)) { echo "here should be the question"; } else { //here move_uploaded_file stuff } Quote Link to comment https://forums.phpfreaks.com/topic/184776-uploading-with-php/ Share on other sites More sharing options...
Adam Posted December 11, 2009 Share Posted December 11, 2009 I assume you mean 'if file exists, overwrite?'.. You could store the temporary file name ($_FILES['tmp_name']) within a session variable, prompt the user, then if they agree "move_uploaded_file". Would it not be better to use a system where you don't get duplicate file names though? Quote Link to comment https://forums.phpfreaks.com/topic/184776-uploading-with-php/#findComment-975463 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2009 Share Posted December 11, 2009 The temp uploaded file is actually deleted automatically when the script on the page that is the target of the form finishes execution, so you would actually need to store the whole temp uploaded file somewhere and a session variable is about the best place if you want it to be automatically deleted once you are finished with it. Quote Link to comment https://forums.phpfreaks.com/topic/184776-uploading-with-php/#findComment-975466 Share on other sites More sharing options...
Adam Posted December 11, 2009 Share Posted December 11, 2009 Actually just found out the file is deleted at the end of the request. In that case then you could move the file to another location, temporarily, while you prompt the user to overwrite the original. Or .. Something as simple as a check box actually as they upload the file could be easier. Edit: Heh, PFMaBiSmAd beat me to it. Quote Link to comment https://forums.phpfreaks.com/topic/184776-uploading-with-php/#findComment-975468 Share on other sites More sharing options...
kat01 Posted December 11, 2009 Author Share Posted December 11, 2009 Thanks all for your answers, I'll carry on with these hints. Quote Link to comment https://forums.phpfreaks.com/topic/184776-uploading-with-php/#findComment-975477 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.