The14thGOD Posted August 2, 2012 Share Posted August 2, 2012 Just as title says, the function returns 1 but when I check the directory it is empty. I moved servers a few months ago and since it's a personal project I didn't bother checking it beyond is everything showing up. Here's the function that handles the file handling: //config define('BASE_ROOT', getenv("DOCUMENT_ROOT")); //project class public function upload_file($file){ $accepted_file_types = array('zip','rar','html','css','js','php','sql','xml','txt'); $ext = explode('.',$file['name']); if(array_search($ext[1],$accepted_file_types) !== false) { $uploaddir = BASE_ROOT."/zips/"; $safename = $this->sanitize_url_string($ext[0]); $file_dir = "$uploaddir".$safename.'_'.date('y-m-d').".$ext[1]"; move_uploaded_file($file['tmp_name'], "$file_dir"); //rename file to be accessed from root $this->old_path = $this->path; $this->path = str_replace(BASE_ROOT,"",$file_dir); } } public function sanitize_url_string($str){ $str = preg_replace('/[^-a-zA-Z0-9_]/','-',$str); $str = preg_replace('/[-]{2,}/','-',$str); $str = strtolower($str); return $str; } I'm hosting on media temple, and the BASE_ROOT is accurate, so I'm not sure where the file is if it's not in the zips folder... Any ideas? Thanks, Justin Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/ Share on other sites More sharing options...
The14thGOD Posted August 2, 2012 Author Share Posted August 2, 2012 crap, sorry, forgot, permissions are all correct too **edit** as well as php ini settings, the file is only 26kb and the correct encryptype is on the form(s) Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366346 Share on other sites More sharing options...
requinix Posted August 2, 2012 Share Posted August 2, 2012 ...You're allowing people to upload PHP scripts? If move_uploaded_file() says it worked then it probably worked. Are you sure you're looking in the right place for the file? Should be /zips/filename_12-08-02.ext. Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366381 Share on other sites More sharing options...
The14thGOD Posted August 2, 2012 Author Share Posted August 2, 2012 Yeah, that's where I'm checking but the file doesn't exist there. Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366388 Share on other sites More sharing options...
The14thGOD Posted August 2, 2012 Author Share Posted August 2, 2012 /home/XXXXXX/domains/example.domain.com/html/zips/filename_12-08-02.zip is the full path, and my unlink function works too. If I remove the BASE_ROOT var I start getting php errors of non existing directories as expected including the unlink function. I've also added the max filesize to the form (found a reported bug, but it was an older version of PHP (current: 5.3.13)). Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366393 Share on other sites More sharing options...
PFMaBiSmAd Posted August 2, 2012 Share Posted August 2, 2012 my unlink function I'm going to guess that the file is moved to the destination, but you also have code that runs and is deleting it. What's your complete code that reproduces the symptom? Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366398 Share on other sites More sharing options...
The14thGOD Posted August 2, 2012 Author Share Posted August 2, 2012 yep..didn't even think of that, I need to adjust the code to delete the file first, then upload. Never ran into the issue before because I never replaced a file the same day. Some of the code didn't work due to a server switch. I had to re-write it after I found out it wasn't working but the db was still updating. This caused it to store today's file name. Seems so easy yet I completely overlooked that. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/266604-move_uploaded_file-returns-true-but-file-is-missing/#findComment-1366404 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.