Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z php error
Forum PHP.pl > Forum > PHP
jasinski214
Witam na początek napisze żę nie wiem czy dobry dział jeśli tak to prosze o przeniesienie.

Taki błąd mi wyskakuje mógł by ktoś powiedzieć jak to naprawićquestionmark.gif



A PHP Error was encountered

Severity: Notice
Message: Undefined index: Content-Length
Filename: libraries/remotefile.php
Line Number: 69


A PHP Error was encountered

Severity: Notice
Message: Undefined index: Content-Length
Filename: libraries/remotefile.php
Line Number: 83

Kod php pliku remotefile.php

  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class CI_Remotefile
  4. {
  5. public $buffer = 204800;
  6. public $tmp_dir = './temp';
  7. public $error = '';
  8. private $headers = '';
  9. public $CI = '';
  10.  
  11. /**
  12. * File Download Constructor
  13. *
  14. * The constructor sets up the download system as ready for files
  15. */
  16. function CI_Remotefile()
  17. {
  18. $this->CI =& get_instance();
  19. log_message('debug', "Remote File Transfer Class Initialized");
  20. }
  21.  
  22. /**
  23. * Setup
  24. *
  25. * Sets Config Vars
  26. *
  27. * @access public
  28. * @param Config Array
  29. * @return null
  30. */
  31. function setup($config = array())
  32. {
  33. if (count($config) > 0)
  34. {
  35. $this->_initialize($config);
  36. }
  37. }
  38.  
  39. function getHeaders($url)
  40. {
  41. $this->headers = get_headers($url, true);
  42. return $this->headers['Content-Length'];
  43. }
  44.  
  45. function headersToArray($string)
  46. {
  47. $lines = explode("\n", $string);
  48. foreach( $lines as $line)
  49. {
  50. $header = explode(":", $line);
  51. $this->headers[$header[0]] = (isset($header[1]) ? $header[1] : '' );
  52. }
  53. }
  54.  
  55. function remoteSize()
  56. {
  57. return $this->headers['Content-Length'];
  58. }
  59.  
  60. function getReferer()
  61. {
  62. if(isset($this->headers['Referer']))
  63. {
  64. return $this->headers['Referer'];
  65. }
  66. else
  67. {
  68. return false;
  69. }
  70. }
  71.  
  72. function isRedirect()
  73. {
  74. if(isset($this->headers['Location']))
  75. {
  76. return $this->headers['Location'];
  77. }
  78. else
  79. {
  80. return false;
  81. }
  82. }
  83.  
  84. function fetchFile($url, $fid, $max_size, $fp=NULL)
  85. {
  86. $parsedurl = parse_url($url, PHP_URL_SCHEME);
  87.  
  88. if($parsedurl == 'http')
  89. {
  90. return $this->_httpTransfer($url, $fid, $max_size, $fp);
  91. }
  92. else if($parsedurl == 'ftp')
  93. {
  94. return $this->_ftpTransfer($url, $fid, ($max_size * 1024 * 1024));
  95. }
  96. else
  97. {
  98. }
  99. }
  100.  
  101. private function _httpTransfer($url, $fid, $max_size, $fp=NULL)
  102. {
  103. $nurl = $url;
  104. $parsedurl = parse_url($url);
  105. if(isset($parsedurl['user']))
  106. {
  107. $user = $parsedurl['user'];
  108. }
  109.  
  110. if(isset($parsedurl['pass']))
  111. {
  112. $pass = $parsedurl['pass'];
  113. }
  114.  
  115. $host = $parsedurl["host"];
  116. $hostname = $host;
  117. $port = "80";
  118. $query = "";
  119. $port = $port ? $port : "80";
  120.  
  121. // Follow redirection
  122. $this->getHeaders($url);
  123. $isRedi = false;
  124. while($this->isRedirect())
  125. {
  126. $nurl = $this->isRedirect();
  127. $isRedi = true;
  128. $this->getHeaders($nurl);
  129. }
  130.  
  131. if($isRedi)
  132. {
  133. $url = $nurl;
  134. $parsedurl = parse_url($url);
  135.  
  136. // Get items of new url
  137. $referer = $this->getReferer();
  138. $host = $parsedurl["host"];
  139. $hostname = $host;
  140. $port = $port ? $port : "80";
  141. }
  142.  
  143. $sh = fsockopen($host, $port, $errid, $errmsg, 30);
  144. if (!$sh)
  145. {
  146. return false;
  147. }
  148.  
  149. if (!$parsedurl["path"])
  150. {
  151. $parsedurl["path"] = "/";
  152. }
  153.  
  154. $request = "";
  155. $request.= "GET ".$parsedurl["path"].(isset($parsedurl["query"]) ? '?'.$parsedurl["query"] : '')." HTTP/1.0\r\n";
  156. $request.= "Host: $hostname\r\n";
  157.  
  158. if (isset($referer) && $referer != "")
  159. {
  160. $request.= "Referer: ".$referer."\r\n";
  161. }
  162.  
  163. if (isset($pass) || isset($user))
  164. {
  165. $request.= "Authorization: Basic ".base64_encode($user.":".$pass)."\r\n";
  166. }
  167.  
  168. $request.= "\r\n";
  169.  
  170. //Send The Request
  171. fwrite($sh, $request);
  172.  
  173. // if no filepointer is given, make a temp file and open it for writing
  174. if(!$fp)
  175. {
  176. $sendFileName = true;
  177. $tmpfname = tempnam($this->tmp_dir, "RFT-");
  178. $fp = fopen($tmpfname, "wb");
  179. }
  180.  
  181. $size = $this->remoteSize();
  182. if($size > ($max_size * 1024*1024))
  183. {
  184. fclose($sh);
  185. fclose($fp);
  186. return false;
  187. }
  188.  
  189. $this->CI->db->insert('progress', array('progress' => 0, 'curr_time' => $_SERVER['REQUEST_TIME'] , 'total' => $size, 'start_time' => $_SERVER['REQUEST_TIME'], 'fid' => $fid));
  190.  
  191.  
  192. $i = $p = 0;
  193. $endHeaders = false;
  194. $rstr='';
  195. // download the file
  196. while(!feof($sh))
  197. {
  198. $string = fread($sh, $this->buffer);
  199. if(!$endHeaders)
  200. {
  201. if($test = stristr($string, "\r\n\r\n"))
  202. {
  203. if($isRedi)
  204. {
  205. $headers = explode("\r\n\r\n", $string);
  206. $headers = $headers[0];
  207. $this->headersToArray($headers);
  208. $size = $this->remoteSize();
  209. $this->CI->db->where('fid', $fid);
  210. $this->CI->db->update('progress', array('total' => $size));
  211. }
  212. $string = str_replace("\r\n\r\n", '', $test);
  213. $endHeaders = true;
  214. }
  215. else
  216. {
  217. continue;
  218. }
  219. }
  220. $p += strlen($string);
  221. fwrite($fp, $string);
  222. $string = NULL;
  223. if($i % 10 == 0)
  224. {
  225. $this->CI->db->where('fid', $fid);
  226. $this->CI->db->update('progress', array('progress' => $p, 'curr_time' => time()));
  227. }
  228. }
  229. fclose($sh);
  230. fclose($fp);
  231.  
  232. // if passed a file pointer return true, if not return temp file name
  233. if(!$sendFileName)
  234. {
  235. return true;
  236. }
  237. else
  238. {
  239. return $tmpfname;
  240. }
  241. }
  242.  
  243. private function _ftpTransfer($url, $fid, $max_size, $fp=NULL)
  244. {
  245. $url = trim($url);
  246. $nurl = $url;
  247. $parsedurl = parse_url($url);
  248.  
  249. $user = "anonymous";
  250. if(isset($parsedurl['user']))
  251. {
  252. $user = $parsedurl['user'];
  253. }
  254.  
  255. $pass = 'xtraupload.v2@gmail.com';
  256. if(isset($parsedurl['pass']))
  257. {
  258. $pass = $parsedurl['pass'];
  259. }
  260.  
  261. $host = $hostname = $parsedurl["host"];
  262. $port = isset($parsedurl["port"]) ? $parsedurl["port"] : "21";
  263. $path = substr($parsedurl['path'], 1);
  264.  
  265. $this->CI->load->library('ftp');
  266.  
  267. $config['hostname'] = $hostname;
  268. $config['username'] = $user;
  269. $config['password'] = $pass;
  270. $config['port'] = $port;
  271. $config['passive'] = TRUE;
  272. $config['debug'] = FALSE;
  273. $this->CI->ftp->connect($config);
  274.  
  275. if($this->CI->ftp->error)
  276. {
  277. $error = $this->CI->ftp->get_error();
  278. log_message('error', $error);
  279. $this->error = $error;
  280. show_error($error);
  281. return false;
  282. }
  283.  
  284. $size = $this->CI->ftp->remote_filesize($path);
  285. if(!$size or ($max_size < $size))
  286. {
  287. log_message('error', "CAN NOT FTP SIZE");
  288. show_error("CAN NOT FTP SIZE");
  289. $this->error = 'CAN NOT FTP SIZE';
  290. return false;
  291. }
  292.  
  293. $this->CI->db->insert('progress',
  294. 'progress' => 0,
  295. 'curr_time' => $_SERVER['REQUEST_TIME'],
  296. 'total' => $size,
  297. 'start_time' => $_SERVER['REQUEST_TIME'],
  298. 'fid' => $fid)
  299. );
  300.  
  301. $fname = $this->CI->ftp->download_xu2($path, $fid, $max_size);
  302. if(!$fname)
  303. {
  304. $this->error = 'CAN NOT FTP TRANSFER';
  305. log_message('error', "CAN NOT FTP TRANSFER");
  306. show_error("CAN NOT FTP TRANSFER");
  307. return false;
  308. }
  309.  
  310. $this->CI->ftp->close();
  311.  
  312. return $fname;
  313. }
  314. }
  315. ?>


Pomożę ktoś albo da chodziaż jakąś wzkazówke?
ADeM
Zrób dokładnie tak jak z resztą:
  1. if(isset($this->headers['Location']))
  2. {
  3. return $this->headers['Location'];
  4. }
  5. else
  6. {
  7. return false;
  8. }

Czego Ci brakuje przy "Content-Length"?
crocodillo
Cytat(ADeM @ 16.10.2011, 17:30:51 ) *
Zrób dokładnie tak jak z resztą:
  1. if(isset($this->headers['Location']))
  2. {
  3. return $this->headers['Location'];
  4. }
  5. else
  6. {
  7. return false;
  8. }

Czego Ci brakuje przy "Content-Length"?

Lub poczytaj o raportowaniu błędów, to nie jest błąd krytyczny, lecz tylko ostrzeżenie
ADeM
Błędów lepiej się pozbyć, a nie chować.
crocodillo
Cytat(ADeM @ 16.10.2011, 18:01:46 ) *
Błędów lepiej się pozbyć, a nie chować.

Tylko, że to nie jest błąd, tylko ostrzeżenie. Jak kto woli, ja osobiście zawsze wyłączam przy raportowaniu E_NOTICE, głównie ze względu właśnie na tablice, gdyż czasami jest po prostu wygodniej robić coś bez sprawdzania, czy dany element w tablicy został zadeklarowany. Kwestia przyzwyczajenie - nie ma nic w tym złego.
jasinski214
sorki jestem troche zielony mógł byś podać jak mam zmienić ten kod tzn cały zmieniony wkleić
nospor
Cytat
Kwestia przyzwyczajenie - nie ma nic w tym złego.
Ta, jasne.... a potem tych błędów uzbiera sie dwa ekrany na monitorze i weź potem znajdź cokolwiek (jak już włączysz wyświetlanie tych błędów, bo czasami bez tego się nie obejdzie)
Tu się trochę na ten temat rozpisałem
http://nospor.pl/notice-wyswietlac-czy-nie.html

@jasinski214 lepiej nie idź za radą crocodillo

ADeM podał ci rozwiązanie
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.