Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z plikiem szablonu
Forum PHP.pl > Forum > PHP
Darnok017
Hej wszystkim,

Jeżeli to o czym piszę jest nie w temacie, bądź nie powinienem o to pytać, to przepraszam i proszę o zamknięcie tematu.

Mam problem. Na serwerze zablokowane jest url_fopen i zdjęcia na stronie nie wyświetlają się.
Instrukcja warunkowa w skrypcie szablonu niestety nie działa i nie ciągnie zdjęć poprzez cURL.
Przedstawiam kod pliku, który wywala następujący błąd

Warning: get_headers(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/users/webs/xxx/wp-content/themes/im-startup/framework/functions/image_cache.php on line 314

A tutaj kod:

  1. <?php
  2. .....
  3.  
  4. if ( ! function_exists( 'miss_image_by_attachment' ) ) {
  5. function miss_image_by_attachment() {
  6. $attachments = get_children(array(
  7. 'post_parent' => get_the_ID(),
  8. 'post_status' => 'inherit',
  9. 'post_type' => 'attachment',
  10. 'post_mime_type' => 'image',
  11. 'order' => 'ASC',
  12. 'orderby' => 'menu_order ID',
  13. 'numberposts' => 1
  14. ));
  15.  
  16. if ( empty( $attachments ) )
  17. return false;
  18.  
  19. foreach ( $attachments as $id => $attachment ) {
  20. $image = wp_get_attachment_image_src( $id, '' );
  21. $image_tags = miss_post_image_tags( $id );
  22. $alt = $image_tags['alt'];
  23. }
  24.  
  25. return array( 'url' => $image[0], 'alt' => $alt );
  26. }
  27. }
  28.  
  29. /**
  30.  *
  31.  */
  32. if ( ! function_exists( 'miss_post_image_tags' ) ) {
  33. function miss_post_image_tags( $image_id, $post_id = '' ) {
  34.  
  35. # Check to is if attachment image has alt
  36. $alt = '';
  37. $file_name = '';
  38. if( is_numeric( $image_id ) ) {
  39. $alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
  40. $alt = esc_attr(trim( $alt ));
  41. }
  42.  
  43. # If no alt generate from file name
  44. if( empty( $alt ) ) {
  45. $file = get_attached_file( $image_id );
  46. $info = pathinfo( $file );
  47. if( isset( $info['extension'] ) )
  48. $file_name = basename( $file, '.' . $info['extension'] );
  49.  
  50. if( !empty( $file_name ) )
  51. $alt = esc_attr(ucwords(str_replace( '-', ' ', str_replace( '_', ' ', $file_name ) )));
  52. }
  53.  
  54. # Generate title tag from post title
  55. $title = '';
  56.  
  57. if( !empty( $post_id ) )
  58. $title = esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) );
  59.  
  60. return array( 'title' => $title, 'alt' => $alt );
  61. }
  62. }
  63.  
  64. /**
  65.  *
  66.  */
  67. if ( ! function_exists( 'miss_display_image' ) ) {
  68. function miss_display_image( $args = array() ) {
  69. if ( !defined('THEME_HIRES') ) {
  70. define( 'THEME_HIRES', ( ( miss_get_setting('hires') == 'enabled') ? 2 : 1 ) );
  71. }
  72.  
  73. global $wp_query, $irish_framework_params;
  74.  
  75. extract( $args );
  76.  
  77. $noimage = isset( $noimage ) ? $noimage : false;
  78.  
  79. if ( ( empty( $src ) && empty( $video_src ) && $noimage == true ) || ( empty( $src ) && empty( $video_src ) && !is_single() ) ) {
  80. return '<img src="' . miss_wp_image( THEME_IMAGES_ASSETS . '/general/no-thumbnail.png' , $width, $height ) . '" />';
  81. }
  82. if ( empty( $src ) && empty( $video_src ) ) {
  83. return;
  84. }
  85. if ( empty( $src ) && !empty( $video_src ) )
  86. {
  87. $out = miss_video( array( 'url' => $video_src, 'width' => $width, 'height' => $height, 'parse' => true, 'video_controls' => $video_controls ) );
  88. } else {
  89. $image = $src;
  90.  
  91. //Trying to build array from string
  92.  
  93. //$home_url = get_home_url() . '/';
  94.  
  95. $home_url = home_url( '/' );
  96.  
  97. if ( defined('ICL_LANGUAGE_CODE') ) {
  98. $home_url = str_replace('/' . ICL_LANGUAGE_CODE . '/','/',$home_url);
  99. }
  100.  
  101.  
  102. $image_path = explode( $home_url, $image );
  103.  
  104. //For local images
  105. if( !empty( $image_path[1] ) ) {
  106. // In this case we'll define image ABSOLUTE PATH
  107. // $image_path = $_SERVER['DOCUMENT_ROOT'] . $image_path[1];
  108. $image_path = ABSPATH . $image_path[1];
  109. $image_info = @getimagesize( $image_path );
  110. } else {
  111. // In this case we'll define iamge URI
  112. if( function_exists('curl_init') ) {
  113. $image_path = $image;
  114. $image_info = @getimagesize( $image );
  115. //if allow_url_fopen is off trying to reach curl
  116. Linia 314->> $image_headers = get_headers( $image, 1 );
  117. if ( $image_headers['Content-Type'] == "image/jpeg" ) {
  118. $remote_extrnsion = ".jpg";
  119. }
  120.  
  121. if ( $image_headers['Content-Type'] == "image/gif" ) {
  122. $remote_extrnsion = ".gif";
  123. }
  124.  
  125. if ( $image_headers['Content-Type'] == "image/png" ) {
  126. $remote_extrnsion = ".png";
  127. }
  128.  
  129. if ( is_writable( THEME_CACHE ) ) {
  130. if ( !file_exists( THEME_CACHE . '/downloads' ) ) {
  131. if ( @mkdir( THEME_CACHE . '/downloads' ) ) {
  132. // Crete safe index
  133. @touch( THEME_CACHE . '/downloads/index.html' );
  134. }
  135. }
  136. $image_downloads = THEME_CACHE . '/donwloads';
  137. } else {
  138. $image_downloads = THEME_CACHE;
  139. }
  140.  
  141. // Trying to reach local file
  142. if ( file_exists( $image_downloads . '/' . md5( $image ) . $remote_extension ) ) {
  143. $image_path = $image_downloads . '/' . md5( $image ) . $remote_extension;
  144. $image_info = @getimagesize( $image_path );
  145. } else {
  146. if ( isset( $remote_extension ) && !empty( $remote_extension ) ) {
  147. $image_downloads .= '/' . md5( $image ) . $remote_extension;
  148.  
  149. $ch = curl_init ( $image );
  150. curl_setopt($ch, CURLOPT_HEADER, 0);
  151. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  152. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  153. $image_raw_data = curl_exec($ch);
  154. curl_close ($ch);
  155.  
  156. //Unlinking if file exists
  157. if(file_exists($image_downloads)){
  158. unlink($image_downloads);
  159. }
  160. // $fp = fopen($image_downloads,'x');
  161. // fwrite($fp, $image_raw_data);
  162. // fclose($fp);
  163.  
  164. $image_path = $image_downloads;
  165. $image_info = @getimagesize( $image_path );
  166.  
  167. }
  168. }
  169. } else {
  170.  
  171. }
  172.  
  173. }
  174.  
  175. ...
  176. ?>
  177.  


Proszę o pomoc, bo już nie wiem co mam robić, a deadline projektu się kończy :/
qbas-s
spróbuj w htaccess dać php_value allow_url_fopen On

lub jeśli masz suPHP możesz w katalogu strony utworzyć php.ini i dać allow_url_fopen = On
Darnok017
Niestety nie mam uprawnień.
Wywala mi błąd 500, abym skontaktował się z administratorem serwera :/
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.