89 $this->data = array();
91 if (file_exists($this->fileName)) {
111 public function read()
113 $lines = readLines($this->fileName, $this->fileEncoding);
116 foreach ($lines as $line) {
117 $fields = preg_split(
'/\s+/', $line);
118 if (
count($fields) == 3) {
121 array(
'url' => $fields[0],
122 'length' => $fields[1],
123 'filename' => $fields[2])
127 $this->data = $fetch;
135 public function write()
139 foreach ($this->data as $fetch) {
140 $data = array($fetch[
'url'], $fetch[
'length'], $fetch[
'filename']);
141 array_push($lines, join(
' ',
$data) .
"\n");
144 if (count($lines) == 0) {
145 if (file_exists($this->fileName)) {
146 unlink($this->fileName);
149 writeFileText($this->fileName, $this->fileEncoding, join(
'', $lines));
158 public function clear()
160 $this->data = array();
161 file_put_contents($this->fileName,
'');
173 public function add($url, $filename)
177 array(
'url' => $url,
'length' =>
'-',
'filename' => $filename)
190 $basedir = dirname($this->fileName);
191 foreach ($this->data as $fetch) {
192 $filename = $basedir .
'/' . $fetch[
'filename'];
193 if (! file_exists($filename)) {
194 $this->_downloadFile($fetch[
'url'], $filename);
211 private function _downloadFile($url, $filename)
213 $dirname = dirname($filename);
214 if (! is_dir($dirname)) {
215 mkdir($dirname, 0777,
true);
217 saveUrl($url, $filename);