2016-04-14 1 views
0

У меня есть одна проблема при загрузке моего веб-сервера. В localhost он работает нормально.Dir Restricted при использовании imagepng PHP GD

В основном моя функция - обновлять изображение с изображением, а затем сохранять в новом имени файла (изображения).

PHP скрипт:

 function updateimage() 
    { 


    //Try retriving data: 
    $ip = $this->input->ip_address(); 
    $this->session->set_userdata("my_session_id", md5($ip)); 
    $ip = $this->session->userdata('my_session_id') ; 




      $text1 = strtoupper ($this->input->post('text1')); 
      $text2 = strtoupper ($this->input->post('text2')); 
      $text3 = strtoupper ($this->input->post('text3')); 


      $text1_align = $this->input->post('text1_align'); 
      $text2_align = $this->input->post('text2_align'); 
      $text3_align = $this->input->post('text3_align'); 



      $text1split = str_split($text1,1); 
      $text2split = str_split($text2,1); 
      $text3split = str_split($text3,1);    


      $image_tag = base_url().'images/tag.png'; 
      $image_A = base_url().'images/A.png'; 
      $image_B = base_url().'images/B.png'; 
      $image_C = base_url().'images/C.png'; 
      $image_D = base_url().'images/D.png'; 
      $image_E = base_url().'images/E.png'; 
      $image_F = base_url().'images/F.png'; 
      $image_G = base_url().'images/G.png'; 
      $image_H = base_url().'images/H.png'; 
      $image_I = base_url().'images/I.png'; 
      $image_J = base_url().'images/J.png'; 
      $image_K = base_url().'images/K.png'; 
      $image_L = base_url().'images/L.png'; 
      $image_M = base_url().'images/M.png'; 
      $image_N = base_url().'images/N.png'; 
      $image_O = base_url().'images/O.png'; 
      $image_P = base_url().'images/P.png'; 
      $image_Q = base_url().'images/Q.png'; 
      $image_R = base_url().'images/R.png'; 
      $image_S = base_url().'images/S.png'; 
      $image_T = base_url().'images/T.png'; 
      $image_U = base_url().'images/U.png'; 
      $image_V = base_url().'images/V.png'; 
      $image_W = base_url().'images/W.png'; 
      $image_X = base_url().'images/X.png'; 
      $image_Y = base_url().'images/Y.png'; 
      $image_Z = base_url().'images/Z.png';   

      $image_1 = imagecreatefrompng($image_tag); 


      imagealphablending($image_1, true); 
      imagesavealpha($image_1, true); 

      $text1len = (strlen($text1)*16)/2; 
      $counter2 = (157 - ($text1len))+strlen($text1); 

      if ($text1_align == 'on') $counter = 70; else $counter = $counter2; 



     if ($text1split) { 
      foreach ($text1split as $text1) 
      { 
      if ($text1 == 'A') { 
        $image_2 = imagecreatefrompng($image_A); 
       imagecopy($image_1, $image_2, $counter, 50, 0, 0, 16, 24); 
      }else if ($text1 == 'B'){ 
       $image_3 = imagecreatefrompng($image_B); 
       imagecopy($image_1, $image_3, $counter, 50, 0, 0, 16, 24); 
      }else if ($text1 == 'C') { 
       $image_4 = imagecreatefrompng($image_C); 
      imagecopy($image_1, $image_4, $counter, 50, 0, 0, 16, 24); 
     } else if ($text1 == 'D') { 
      $image_5 = imagecreatefrompng($image_D); 
      imagecopy($image_1, $image_5, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'E') { 
      $image_6 = imagecreatefrompng($image_E); 
      imagecopy($image_1, $image_6, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'F') { 
      $image_7 = imagecreatefrompng($image_F); 
      imagecopy($image_1, $image_7, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'G') { 
      $image_8 = imagecreatefrompng($image_G); 
      imagecopy($image_1, $image_8, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'H') { 
      $image_9 = imagecreatefrompng($image_H); 
      imagecopy($image_1, $image_9, $counter, 50, 0, 0, 16, 24); 
      }else if ($text1 == 'I') { 
      $image_10 = imagecreatefrompng($image_I); 
       imagecopy($image_1, $image_10, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'J') { 
      $image_11 = imagecreatefrompng($image_J); 
      imagecopy($image_1, $image_11, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'K') { 
      $image_12 = imagecreatefrompng($image_K); 
      imagecopy($image_1, $image_12, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'L') { 
      $image_13 = imagecreatefrompng($image_L); 
      imagecopy($image_1, $image_13, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'M') { 
      $image_14 = imagecreatefrompng($image_M); 
      imagecopy($image_1, $image_14, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'N') { 
      $image_15 = imagecreatefrompng($image_N); 
      imagecopy($image_1, $image_15, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'O') { 
      $image_16 = imagecreatefrompng($image_O); 
      imagecopy($image_1, $image_16, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'P') { 
      $image_17 = imagecreatefrompng($image_P); 
      imagecopy($image_1, $image_17, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'Q') { 
      $image_18 = imagecreatefrompng($image_Q); 
      imagecopy($image_1, $image_18, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'R') { 
      $image_19 = imagecreatefrompng($image_R); 
      imagecopy($image_1, $image_19, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'S') { 
      $image_20 = imagecreatefrompng($image_S); 
      imagecopy($image_1, $image_20, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'T') { 
      $image_21 = imagecreatefrompng($image_T); 
      imagecopy($image_1, $image_21, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'U') { 
      $image_22 = imagecreatefrompng($image_U); 
      imagecopy($image_1, $image_22, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'V') { 
      $image_23 = imagecreatefrompng($image_V); 
      imagecopy($image_1, $image_23, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'W') { 
      $image_24 = imagecreatefrompng($image_W); 
      imagecopy($image_1, $image_24, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'X') { 
      $image_25 = imagecreatefrompng($image_X); 
      imagecopy($image_1, $image_25, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'Y') { 
      $image_26 = imagecreatefrompng($image_Y); 
      imagecopy($image_1, $image_26, $counter, 50, 0, 0, 16, 24); 
     }else if ($text1 == 'Z') { 
      $image_27 = imagecreatefrompng($image_Z); 
      imagecopy($image_1, $image_27, $counter, 50, 0, 0, 16, 24); 
     } 
      $counter = $counter+16;  
      }  
     } 



      $text2len = (strlen($text2)*16)/2; 
      $counter2 = (157 - ($text2len))+strlen($text2); 

      if ($text2_align == 'on') $counter = 70; else $counter = $counter2; 

      if ($text2split) { 
      foreach ($text2split as $text1) 
      { 
      if ($text1 == 'A') imagecopy($image_1, $image_2, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'B') imagecopy($image_1, $image_3, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'C') imagecopy($image_1, $image_4, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'D') imagecopy($image_1, $image_5, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'E') imagecopy($image_1, $image_6, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'F') imagecopy($image_1, $image_7, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'G') imagecopy($image_1, $image_8, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'H') imagecopy($image_1, $image_9, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'I') imagecopy($image_1, $image_10, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'J') imagecopy($image_1, $image_11, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'K') imagecopy($image_1, $image_12, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'L') imagecopy($image_1, $image_13, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'M') imagecopy($image_1, $image_14, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'N') imagecopy($image_1, $image_15, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'O') imagecopy($image_1, $image_16, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'P') imagecopy($image_1, $image_17, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'Q') imagecopy($image_1, $image_18, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'R') imagecopy($image_1, $image_19, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'S') imagecopy($image_1, $image_20, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'T') imagecopy($image_1, $image_21, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'U') imagecopy($image_1, $image_22, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'V') imagecopy($image_1, $image_23, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'W') imagecopy($image_1, $image_24, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'X') imagecopy($image_1, $image_25, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'Y') imagecopy($image_1, $image_26, $counter, 75, 0, 0, 16, 24); 
      else if ($text1 == 'Z') imagecopy($image_1, $image_27, $counter, 75, 0, 0, 16, 24); 

      $counter = $counter+16;  
      }  
     } 


      $text3len = (strlen($text3)*16)/2; 
      $counter2 = (157 - ($text3len))+strlen($text3); 

      if ($text3_align == 'on') $counter = 70; else $counter = $counter2; 

      if ($text3split) { 
      foreach ($text3split as $text1) 
      { 
      if ($text1 == 'A') imagecopy($image_1, $image_2, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'B') imagecopy($image_1, $image_3, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'C') imagecopy($image_1, $image_4, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'D') imagecopy($image_1, $image_5, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'E') imagecopy($image_1, $image_6, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'F') imagecopy($image_1, $image_7, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'G') imagecopy($image_1, $image_8, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'H') imagecopy($image_1, $image_9, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'I') imagecopy($image_1, $image_10, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'J') imagecopy($image_1, $image_11, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'K') imagecopy($image_1, $image_12, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'L') imagecopy($image_1, $image_13, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'M') imagecopy($image_1, $image_14, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'N') imagecopy($image_1, $image_15, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'O') imagecopy($image_1, $image_16, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'P') imagecopy($image_1, $image_17, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'Q') imagecopy($image_1, $image_18, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'R') imagecopy($image_1, $image_19, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'S') imagecopy($image_1, $image_20, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'T') imagecopy($image_1, $image_21, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'U') imagecopy($image_1, $image_22, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'V') imagecopy($image_1, $image_23, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'W') imagecopy($image_1, $image_24, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'X') imagecopy($image_1, $image_25, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'Y') imagecopy($image_1, $image_26, $counter, 100, 0, 0, 16, 24); 
      else if ($text1 == 'Z') imagecopy($image_1, $image_27, $counter, 100, 0, 0, 16, 24); 

      $counter = $counter+16;  
      }  
     } 

       $path = $_SERVER['DOCUMENT_ROOT']."\simtag\images/".$ip."tag2.png"; 

echo "Dir: " . dirname($path) . "<br />"; 
echo "File: " . $path . "<br />"; 

$seperator = '<br>';// and this 

echo (is_writable(dirname($path))?'DIR writeable':'dir Restricted') . $seperator; 
if(! file_exists($path)) 
    die('File does not exist'); 

echo is_writable($path)?'File writeable':'File has insufficient perms'; 
die(); 

      $this->save_imagepng($image_1,$path); 
      //imagepng($image_1, $path); 
       imagedestroy($image_1); 

      redirect('home'); 

    } 

function save_imagepng($img,$fname) 
{ 
    ob_start();// store output 
    imagepng($img);// output to buffer 
    file_put_contents($fname, ob_get_contents(), FILE_BINARY);// write buffer to file 
    ob_end_clean();// clear and turn off buffer 
} 

Когда не работает его ничего не произошло, то я проверяю папку записываемой или не оно приходит как этот

Dir: /home/kagasiac/public_html\simtag\images 
File: /home/kagasiac/public_html\simtag\images/44801aed40d934e6b15c89a2363cc9abtag2.png 
dir Restricted 
File does not exist 

Любая идея?

+0

Не по теме, но я готов поспорить, что вам будет интересно узнать о [switch in PHP] (http://php.net/manual/en/control-structures.switch.php) – larsAnders

+1

Вместо использования DOCUMENT_ROOT вам может потребоваться указать структуру файла, начиная с public_html. Веб-сервер не может ссылаться на каталог DOCUMENT_ROOT. Кроме того, вы перепутали \ и/в пути к файлу. \ является escape-символом, поэтому вам, возможно, придется дважды указывать его \\ simtag \\ images – Brett

+0

спасибо @brett i меняем на $ path = "\\ public_html \\ simtag \\ images \\". $ ip. "tag2. PNG "; но файл сохранен в корневой папке с именем \ public_html \ simtag \ images \ 8973ee1cd414efaff7d0e71b138609a0tag2.png не в папке изображений. – reefman

ответ

0

Просто чтобы люди не читали комментарии к вопросу. Решение было изменить базовый каталог для запуска в public_html и использовать/

Таким образом, для данного примера

$path = "/public_html/simtag/images/".$ip."tag2.png"; 

вместо

$path = $_SERVER['DOCUMENT_ROOT']."\simtag\images/".$ip."tag2.png"; 

Это часто из-за ограничений со стороны сервера. Не удается получить доступ к базовым каталогам в режиме общего хостинга.

 Смежные вопросы

  • Нет связанных вопросов^_^