Jump to content

[SOLVED] Resource ID #3


aschulz90

Recommended Posts

When I try and get the following code to work (it's mostly my own coding actually not third party) the binary file in the table won't work! it says resource id #3 and is only 14bytes which is not the size of the html document I'm uploading here is a link to the php script in a text file:

 

http://ci.durham.nh.us/brokenbinary.txt

 

here is the query creation command for the table:

 

CREATE TABLE binary_data (

id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,

description CHAR(50),

bin_data LONGBLOB,

filename CHAR(50),

filesize CHAR(50),

filetype CHAR(50)

);

(That code was written by an author from phpbuilder.com) the original code is there but I couldn't get it to work as it was I'm thinking because it was PHP3. I've been working at this all day and can't figure out why this just won't work. Thanks for any help.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/160051-solved-resource-id-3/
Share on other sites

This case is resolved! I don't know why I wanted to upload the file as binary that was dumb. Here's the new code and you change the bin_data to some other kind of lengthly text feild.

 

<?php
//Initializers...
//error_reporting(E_ALL);
//ini_set('display_errors', '1');

$errors="";
$_SESSION["knowdis"]="0";
mysql_connect($host,$user,$password);
/* This Function uploads the Document to the Web Server...OR SHOULD!!! */
function Uploader()
{
if (($_FILES["file"]["type"] == "text/html") && ($_FILES["file"]["size"] < 1000000))
{
   if ($_FILES["file"]["error"] > 0){
   echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
   }
  else
	{
	$file = $_FILES["file"];
	$date = $_POST["description"];
	$fileName = $_FILES["file"]["name"];
	$tmpName = $_FILES["file"]["tmp_name"];
	$fileSize = $_FILES["file"]["size"];
	$fileType = $_FILES["file"]["type"];
	$id= mysql_insert_id();
	$data = file_get_contents($tmpName);
	echo($fileSize);
	echo($data);
	$mysql_link = @mysql_connect("xx","xx","xx");
	if (mysql_errno() == 0) { @mysql_select_db("xx", $mysql_link);}

		$sqlcmd = sprintf("INSERT INTO `binary_data`(`id`, `description`, `bin_data`, `filename`, `filesize`, `filetype`) VALUES('%s', '%s', '".$data."', '%s', '%s', '%s')",
						   mysql_real_escape_string($id, $mysql_link),
						   mysql_real_escape_string($date, $mysql_link),
						   //mysql_real_escape_string($data, $mysql_link),
						   mysql_real_escape_string($fileName, $mysql_link),
						   mysql_real_escape_string($fileSize, $mysql_link),
						   mysql_real_escape_string($fileType, $mysql_link));

	@mysql_query($sqlcmd, $mysql_link);

		 if (mysql_errno() > 0) {
			echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
			exit;}
	}
}
else
  {
  echo "<font color=\"#FF0000\">An Error Occurred! The file is either of the wrong type, too large, or is in use.<br>Remember to close out of your word processesor after saving!</font>";
  }
} //**********************END FUNCTION*******************************//


if (($_POST["description"]==""))
{
$first="1";
}
else
{
$first="0";
}


?>
<title>Bianary File Uploader</title><body link="#0000FF" vlink="#0000CC" alink="#0066FF">

<br>
<form action="" method="post" enctype="multipart/form-data">
<br>
<label>File Description:</label><br>
<input name="description" id="description" value="<?php echo($_POST["description"]); ?>">

<br>HTML File Location:<br>
<input type="file" name="file" id="file"  value="<?php echo($_FILES["file"]); ?>"/><br>
<input type="Submit" name="Submit" value="Submit" >
</form>
<?php
if (($first == 0)){Uploader();}
?>

Link to comment
https://forums.phpfreaks.com/topic/160051-solved-resource-id-3/#findComment-844909
Share on other sites

Sorry about that, will do. The code above was only the short version. Here is it finalized for use to migrate html documents to Joomla!'s article database:

 

<?php
//Initializers...
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
//Copyright Adam Schulz 2009


$host="xx";
$user="xx";
$password="xx";
$errors="";
$_SESSION["knowdis"]="0";
mysql_connect($host,$user,$password);


/*******This Function uploads the Document to the MySQL Database*******/
function Uploader()
{
if (($_FILES["file"]["type"] == "text/html") && ($_FILES["file"]["size"] < 1000000))
{
   if ($_FILES["file"]["error"] > 0){
   echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
   }
  else
	{
	$FileName = $_FILES["file"]["name"];
	$tmpName = $_FILES["file"]["tmp_name"];
	$id= mysql_insert_id();
	$title = "Friday Updates";
	$alias = "";
	$title_alias = "";
	$introtext = "";
	$fulltext = file_get_contents($tmpName);
	$state = "1";
	$sectionid = "1";
	$mask = "0";
	$catid = "1";


	//******************NAMING SCRIPT: *****************//	
	$month = substr($FileName,0,2);
	$day = substr($FileName,2,2);
	$year = substr($FileName,4,2);
	$created = "20".$year."-".$month."-".$day." 17:00:00";
	echo $created;
	//****************** END NAMING SCRIPT: *****************//


	$created_by = "62";
	$created_by_alias = "xx";
	$modified = date( 'Y-m-d H:i:s');
	$modified_by = "62";
	$checked_out = "62";
	$checked_out_time = "0000-00-00 00:00:0000";
	$publish_up = $modified;
	$publish_down = $checked_out_time;
	$images = "0";
	$urls = "0";
	$attribs = "show_title=1
link_titles=0
show_intro=1
show_section=
link_section=
show_category=
link_category=
show_vote=
show_author=1
show_create_date=1
show_modify_date=0";
	$version="1";
	$parentid = "0";
	$ordering = "0";
	$metakey = "";
	$metadesc = "";
	$access = "0";
	$hits = "0";
	$metadata = "robots=
author=";

	$mysql_link = @mysql_connect("xx", "xx", "xx");
	if (mysql_errno() == 0) { @mysql_select_db("joomla", $mysql_link);}

		$sqlcmd = sprintf("INSERT INTO `jos_content`(`id`, `title`, `alias`, `title_alias`, `introtext`, `fulltext`, `state`, `sectionid`, `mask`, `catid`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `images`, `urls`, `attribs`, `version`, `parentid`, `ordering`, `metakey`, `metadesc`, `access`, `hits`, `metadata`) VALUES('%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s','%s','%s', '%s', '%s', '%s','%s','%s')",
						   mysql_real_escape_string($id, $mysql_link),
						   mysql_real_escape_string($title, $mysql_link),
						   mysql_real_escape_string($alias, $mysql_link),
						   mysql_real_escape_string($title_alias, $mysql_link),
						   mysql_real_escape_string($introtext, $mysql_link),
						   mysql_real_escape_string($fulltext, $mysql_link),
						   mysql_real_escape_string($state, $mysql_link),
						   mysql_real_escape_string($sectionid, $mysql_link),
						   mysql_real_escape_string($mask, $mysql_link),
						   mysql_real_escape_string($catid, $mysql_link),
						   mysql_real_escape_string($created, $mysql_link),
						   mysql_real_escape_string($created_by, $mysql_link),
						   mysql_real_escape_string($created_by_alias, $mysql_link),
						   mysql_real_escape_string($modified, $mysql_link),
						   mysql_real_escape_string($modified_by, $mysql_link),
						   mysql_real_escape_string($checked_out, $mysql_link),
						   mysql_real_escape_string($checked_out_time, $mysql_link),
						   mysql_real_escape_string($publish_up, $mysql_link),
						   mysql_real_escape_string($publish_down, $mysql_link),
						   mysql_real_escape_string($images, $mysql_link),
						   mysql_real_escape_string($urls, $mysql_link),
						   mysql_real_escape_string($attribs, $mysql_link),
						   mysql_real_escape_string($version, $mysql_link),
						   mysql_real_escape_string($parentid, $mysql_link),
						   mysql_real_escape_string($ordering, $mysql_link),
						   mysql_real_escape_string($metakey, $mysql_link),
						   mysql_real_escape_string($metadesc, $mysql_link),
						   mysql_real_escape_string($access, $mysql_link),
						   mysql_real_escape_string($hits, $mysql_link),
						   mysql_real_escape_string($metadata, $mysql_link));


	@mysql_query($sqlcmd, $mysql_link);

		 if (mysql_errno() > 0) {
			echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
			exit;}
	}
}
else
  {
  echo "<font color=\"#FF0000\">An Error Occurred! The file is either of the wrong type, too large, or is in use.<br>Remember to close out of your word processesor after saving!</font>";
  }
} //**********************END OF FUNCTION*******************************//


if ($_FILES["file"]=="")
{
$first="1";
}
else
{
$first="0";
}


?>
<title>Friday Updates Migrator</title><body link="#0000FF" vlink="#0000CC" alink="#0066FF">
<h2>Friday Updates Migrator V1.0</h2>
<br>
<form action="" method="post" enctype="multipart/form-data">
<br>
<br>HTML File Location:<br>
<input type="file" name="file" id="file"  value="<?php echo($_FILES["file"]); ?>"/><br>
<input type="Submit" name="Submit" value="Submit" >
</form>
<?php
if (($first == 0)){uploader();}
?>

Link to comment
https://forums.phpfreaks.com/topic/160051-solved-resource-id-3/#findComment-845124
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.