Jump to content

Recommended Posts

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

...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.

/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)).

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.