public function remote($source) { if ($this->file != NULL) { throw new Exception(); } $this->file = File::createFilename(); $this->time = time(); $this->uid = System::getUser()->uid; // Add http:// is necessary if (substr($source, 0, 7) == 'http://') { } elseif (substr($source, 0, 8) == 'https://') { } elseif (substr($source, 0, 6) == 'ftp://') { } else { $source = 'http://' . $source; } // Download file $rh = @fopen($source, 'r'); $wh = @fopen(SYSTEM_ROOT . File::FILEDIR . $this->file, 'w+'); if ($rh === false) { throw new UploadException('CannotOpenDomain'); return; } if ($wh === false) { Log::sysLog("File", "Cannot write for remote upload"); throw new UploadException('CannotOpenWriteFile'); return; } while (!feof($rh)) { if (fwrite($wh, fread($rh, 1024)) === FALSE) { throw new UploadException('CannotWrite'); return; } } fclose($rh); fclose($wh); // Determine MIME type $this->mime = File::determineMime(SYSTEM_ROOT . File::FILEDIR . $this->file); if ((empty($this->mime) || $this->mime == 'application/octet-stream') && !empty($http_response_header) && is_array($http_response_header)) { foreach ($http_response_header as $key => $value) { if (substr($value, 0, 14) == 'Content-Type: ') { $pos = strpos($value, ';'); if ($pos === false) { $this->mime = substr($value, 14); } else { $this->mime = substr($value, 14, $pos - 14); } } } } $this->size = filesize($this->getAbsPath()); // Generate hashes foreach (explode(',', SUPPORTED_FILE_HASHES) as $value) { $this->hashes[$value] = hash_file($value, SYSTEM_ROOT . File::FILEDIR . $this->file); } }