2012-10-16 75 views
0

大家好,我把一些代碼的Joomla文件,我現在面臨一個問題,即目標路徑和文件夾的權限是正確的,雖然文件沒有被上傳文件上傳問題,權限是否正確

這裏代碼

$avatar_file = JRequest::getVar('image', null, 'files','array'); 
      $upfilename= str_replace($replace,'_',$avatar_file['name']); 
      //echo JPATH_ROOT.DS.'images'.DS.'easyblog_avatar'.DS; 
      //exit; 
      print_r($_FILES); 
      $arr = '{"google_profile_url":"","show_google_profile_url":""}'; 
      echo is_uploaded_file($_FILES['image']['tmp_name']).'<br>'. 
      //$destFilePath = dirname(dirname(dirname(dirname(__FILE__)))).DS.'images'.DS.'easyblog_avatar'.DS.$user_id.'_'.$upfilename; 
      $destFilePath = JPATH_ROOT.DS.'images'.DS.'easyblog_avatar'.DS.$user_id.'_'.$upfilename; 
      //if(JFile::upload($avatar_file['tmp_name'], JPATH_ROOT.DS.'images'.DS.$user_id.'_'.$upfilename)){ 
      if(@move_uploaded_file($_FILES['image']['tmp_name'], $destFilePath)){ 
       $avatar = $user_id.'_'.$upfilename; 
      } 

我同時使用joomla函數和核心函數上傳文件,但它不是上傳。

請幫幫我。

感謝

+0

您是否獲得$ _FILES? – Irfan

+2

「它不上傳」是不夠的信息。你有錯誤嗎?代碼在哪裏失敗?當您想要顯示錯誤時,不建議使用'@'。 – alfasin

+0

@ alfasin是你的正確,但我沒有得到任何錯誤,所以我嘗試'@',雖然我嘗試error_reporting('E_ALL');和ini_set('display_error',1); –

回答

0
//import joomlas filesystem functions, we will do all the filewriting with joomlas functions 
    jimport('joomla.filesystem.file'); 
    jimport('joomla.filesystem.folder'); 

    //this is the name of the field in the html form, filedata is the default name for swfupload 
$fieldName = 'Filedata'; 

    //the name of the file in PHP's temp directory that we are going to move to our folder 
    $fileTemp = $_FILES[$fieldName]['tmp_name']; 


    //always use constants when making file paths, to avoid the possibilty of remote file inclusion 
    $uploadPath = JPATH_SITE.DS.'path'.DS.'path'.DS.$fileName; 

    if(!JFile::upload($fileTemp, $uploadPath)) 
    { 
      echo JText::_('ERROR MOVING FILE'); 
      return; 
    } 
+0

我可以使用'jimport'功能 –

+0

是的,你可以。它工作正常。我剛剛測試過:-) – Techie

+0

文件正在臨時文件夾中上傳,但未移動到目的地是否有任何原因背後呢? –