i have this site which uploads images, but all images get a permission chmod of 66 not 777can ssomeone help me make it uploaded files receives a CHMOD of 777
You should chmod files 0644 and dirs 0755. Are you getting the chmod value from a string? Please post all related code.
im tryin to get the cmod code into this script but i cant do it <?php /* - PHP4 Image upload script - coded by kreoton */ class imageupload { //pblic variables var $path = ''; var $errorStr = ''; var $imgurl = ''; //private variables var $_errors = array(); var $_params = array(); var $_lang = array(); var $_maxsize = 1048576; var $_im_status = false; //public methods function imageupload () { require 'config.php'; $this->_types = $types; $this->_lang = $lang; $this->_upload_dir = $upload_dir; $this->_maxsize = $maxsize; $this->path = $PHP_SELF; if (is_array($_FILES['__upload'])) { $this->_params = $_FILES['__upload']; if (function_exists('exif_imagetype')) $this->_doSafeUpload(); else $this->_doUpload(); if (count($this->_errors) > 0) $this->_errorMsg(); } } function allowTypes () { $str = ''; if (count($this->_types) > 0) { $str = 'Allowed types: ('; $str .= implode(', ', $this->_types); $str .= ')'; } return $str; } // private methods function _doSafeUpload () { preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); if (exif_imagetype($this->_params['tmp_name']) && in_array(strtolower($matches[1]), $this->_types)) { if ($this->_params['size'] > $this->_maxsize) $this->_errors[] = $this->_lang['E_SIZE']; else $this->_im_status = true; if ($this->_im_status == true) { $ext = substr($this->_params['name'], -4); $this->new_name = md5(time()).$ext; move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name; } } else $this->_errors[] = $this->_lang['E_TYPE']; } function _doUpload () { preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); if(in_array(strtolower($matches[1]), $this->_types)) { if ($this->_params['size'] > $this->_maxsize) $this->_errors[] = $this->_lang['E_SIZE']; else $this->_im_status = true; if ($this->_im_status == true) { $ext = substr($this->_params['name'], -3); $this->new_name = md5(time()).$ext; move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name; } } else $this->_errors[] = $this->_lang['E_TYPE']; } function _errorMsg() { $this->errorStr = implode('<br />', $this->_errors); } } ?> can someone help me put the cmod code into it
under both move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); chmod($this->_upload_dir.$this->new_name, 0777); but like MMJ commented; you need to study permissions and think why you would want 777, as world-writable is probably not needed at all.
I am having a smimilar problem but I am getting no such file or directory $file_size=$HTTP_POST_FILES['Picture']['size']; if($file_size<50000) $r=mysql_query("show table status like 'member'"); $id1=mysql_fetch_array($r); $id=$id1['Auto_increment']; $my_file ="usr".$id.".".strtolower($Extension[$ext]); move_uploaded_file($tmp_file,"picture/".$my_file); $image_url = '"picture/".$my_file'; chmod($image_url,0644); $insert="INSERT INTO member SET UserName='".$_REQUEST['UserName']."',Password='".$_REQUEST['Password']."',Email='".$_REQUEST['Email']."',Regdate='".time()."',Picture='".$my_file."'"; $r=mysql_query($insert); if(!session_is_registered("LogedInUserId")) { session_register("LogedInUserId"); PHP: it works without the chmod line but the files are all chmod 600, I just moved severs and the old server didnt need this chmod line
In some environments, we have found that permissions cannot be changed by the web user, typically Apache. Log in via SSH to see who "owns" the files. You can probably use FTP as well. This is what we have seen on "protective" web hosts. Hope that gets you in the right direction. -Bing
I am running VPS so I am able to change my environment, what should i change and where? I currently have a cron job changing permissions every 15 minutes but that doesnt look very professional on a website :| BTW I am clueless about PHP so changing to FTP is going to be difficult for me Sample ls -l output -rw-r--r-- 1 vu2019 vu2019 9272 Feb 20 13:04 usr27.jpg -rw-r--r-- 1 vu2019 vu2019 9510 Feb 20 13:15 usr28.jpg -rw-r--r-- 1 vu2019 vu2019 365354 Feb 20 11:28 usr4.jpg -rw-r--r-- 1 vu2019 vu2019 838291 Feb 20 11:29 usr5.jpg -rw-r--r-- 1 vu2019 vu2019 28506 Feb 20 11:29 usr6.gif -rw-r--r-- 1 vu2019 vu2019 1621 Feb 20 11:29 usr7.gif -rw-r--r-- 1 vu2019 vu2019 5328 Feb 20 11:29 usr8.gif -rw-r--r-- 1 vu2019 vu2019 14497 Feb 20 11:29 usr9.gif PHP:
You should chmod files 644 and dirs 755. If you chmod 777 (can execute), your host will be hacked easily.