$starttime = microtime();

	/* Url or File? */
	 if(is_array($HTTP_POST_FILES) && $HTTP_POST_FILES["file"]["name"] != "") {
		/* File upload */

		/* Always new rsc */
		$tmpRsc = new Rsc;
		$tmpRsc->RscMD5 = new_id();
		$tmpRsc->RscName = $HTTP_POST_FILES["file"]["name"];
		$tmpRsc->IsURL = 0;

		$tmpFname = $dir_rsc."/".$tmpRsc->RscMD5.".infile";

		if (copy($HTTP_POST_FILES["file"]["tmp_name"], $tmpFname) ) {
			echo "";

			/* Perform file voodoo (possible unzip and file type determination) */
			fetch_try_unzip($tmpFname);

			$tmpRsc->RscTypeID = rsc_type($tmpFname);
			$tmpRsc->InCache = -1; // If not failed ...
			$tmpRsc->Size = filesize($tmpFname);
				
			$add_rsc = true;
		} else {
			$tmpRsc->InCache = 0;
			$add_rsc = true;
		}
	}

	if(isset($url)) {
		/* Fetch url */
		if($url == "http://") {
			/* Press back, and enter a real url, or view one of the examples */
			echo "Press back, and enter a real url, or view one of the examples.
"; $got_file = 0; } else { /* If not in cache... */ $sql = "SELECT * FROM Rsc WHERE "; $sql .= "IsURL = -1 AND RscName ='".mysql_escape_string($url)."'"; #DEB echo $sql; $qRsc = mysql_query($sql); if(!$tmpRsc = mysql_fetch_object($qRsc)) { /* Not in cache - add rsc and fetch */ $tmpRsc = new Rsc; $tmpRsc->RscMD5 = new_id(); $tmpRsc->RscName = $url; $tmpRsc->IsURL = -1; $tmpRsc->InCache = 0; $download = true; $add_rsc = true; } else { // Got rsc #DEB echo "Got object
"; if($tmpRsc->InCache) { #DEB echo "In cache. No fetch
"; } else { #DEB echo "Fetch
"; $download = true; $upd_rsc = true; } } if($download) { /* Go get it */ $tmpFname = $dir_rsc.$tmpRsc->RscMD5.".infile"; echo "Downloading...
"; fetch_wget($tmpFname, $url); /* Perform file voodoo (possible unzip and file type determination) */ fetch_try_unzip($tmpFname); $tmpRsc->RscTypeID = rsc_type($tmpFname); $tmpRsc->InCache = -1; // If not failed ... $tmpRsc->Size = filesize($tmpFname); } } } if($add_rsc) { /* Add $tmpRsc to Rsc */ $sql = "INSERT INTO Rsc"; $sql .= " (RscMD5, RscTypeID, RscName, IsURL, InCache, Size)"; $sql .= sprintf(" VALUES ('%s', '%s', '%s', %d, %d, %d)", $tmpRsc->RscMD5, $tmpRsc->RscTypeID, mysql_escape_string($tmpRsc->RscName), $tmpRsc->IsURL, $tmpRsc->InCache, $tmpRsc->Size ); #DEB echo $sql."
"; $q = mysql_query($sql); $tmpRsc->RscID = mysql_insert_id(); } if($upd_rsc) { $sql = "UPDATE Rsc SET RscTypeID=".$tmpRsc->RscTypeID; $sql .= ", InCache=".$tmpRsc->InCache; $sql .= ", Size=".$tmpRsc->Size; $sql .= " WHERE RscID=".$tmpRsc->RscID; #DEB echo $sql."
"; $q = mysql_query($sql); } $stoptime = microtime(); /* Tell rscfetch about this fetch */ $host = mysql_escape_string(substr(GetEnv("REMOTE_HOST"), 0, 254)); $ip = mysql_escape_string(substr(GetEnv("REMOTE_ADDR"), 0, 15)); $req_status = "200"; $req_method = mysql_escape_string(substr(GetEnv("REQUEST_METHOD"), 0, 254)); $request = mysql_escape_string(substr(GetEnv("QUERY_STRING"), 0, 254)); $referer = mysql_escape_string(substr(GetEnv("HTTP_REFERER"), 0, 254)); $user_agent = mysql_escape_string(substr(GetEnv("HTTP_USER_AGENT"), 0, 254)); $sql .= "'$req_status', '$req_method', '$request', '$referer', '$user_agent', '$host', '$ip')"; $sql = "INSERT INTO RscFetch"; $sql .= " (RscID, FetchDate, FromCache, FetchSeconds, Size, req_status, req_method, request, referer, user_agent, host, ip) "; $sql .= sprintf("VALUES ('%s', NOW(), %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $tmpRsc->RscID, ($download || isset($file)) ? 0 : -1, elapsedtime($starttime, $stoptime), $tmpRsc->Size, $req_status, $req_method, $request, $referer, $user_agent, $host, $ip ); # echo $sql."
"; $q = mysql_query($sql); ?> Could not view document. Sorry it didn't work out!