HELP HELP HELP I'm cookoo!

Problems with the Windows version of XAMPP, questions, comments, and anything related.

HELP HELP HELP I'm cookoo!

Postby willaguila » 26. September 2009 18:04

:?:

Hey folks, I got one of those problems with my php/mysql code that has no errors, works perfectly on my hosted server
but doesn't work on my local xampp server. No idea why because I developed it locally and it worked once and then nothing.
Basically it is a simple script that uploads images into a database blob table into 64k byte pieces and another script that downloads
the image off of the database, assembles the chunks and displays it on the web page! Sounds pretty trivial right!

1. Here is the low down for the hosted server: runnning php 5.2.11 and mysql 5.0.67,
scripts are aboslutely working here, image displayed

2. My local xampp dvelopment machine is a windows xp machine with xampp 1.7.2 which uses php 5.3 and mysql 5.1.37,
script produces no errors but a blank page no image

Ok, below are the two exact scripts I'm using plus the upload form and the sql tables. If you have the time
I'd appreciate it because it is really setting my development back? I just need to know if it is a version
problem, a bug problem or am I just cookoo?


--------------------------------------------------------------------------------------------------
Form upload_form.php

<form enctype="multipart/form-data" method="post" action="upload_image.php">
<input type=hidden name=MAX_FILE_SIZE value=99999999>
<input type="file" name="file_upload1" />
<input type="submit" name="submit" value="Upload" />
</form> <br />
---------------------------------------------------------------------------------------------------

upload_image.php

<?php

$db = "image";

if (!$connection = mysql_connect("$db", "image", "")) {
die("Unable to connect to storage server!");
}

if (!mysql_select_db("image", $connection)) {
die("Unable to connect to storage database!");
}


$upload_errors = array(
UPLOAD_ERR_OK => "No Error.",
UPLOAD_ERR_INI_SIZE => "Larger than upload max ini file.",
UPLOAD_ERR_FORM_SIZE => "Larger Than MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file sent.",
UPLOAD_ERR_NO_TMP_DIR => "No tmp directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);


if(isset($connection)) { echo "true";} else { echo "false";}
echo"<br />";

echo "DB connection is working!" . "<br />";

//Start of a while loop:
$STARTFILE = 1;
$ONFILE = "file_upload" . $STARTFILE;
date_default_timezone_set('America/New_York');

// while (isset($_FILES["$ONFILE"])) {

$bin_filepath = $_FILES["$ONFILE"]['tmp_name'];
$bin_filetype = $_FILES["$ONFILE"]['type'];
$bin_filename = $_FILES["$ONFILE"]['name'];




clearstatcache(); //clears cache on file being checked multiple times.
$file_time = filemtime($bin_filepath);
$file_date = date("Y-m-d H:i:s", $file_time);

$sql = "INSERT INTO file (datatype, name, size, filedate) VALUES ('";
$sql .= $bin_filetype . "', '" . $bin_filename . "', " . filesize($bin_filepath);
$sql .= ", '" . $file_date . "')";

if(!$res = mysql_query($sql, $connection)) {
die("Failure to insert to file table!");

} else {

echo "The following sql statment was executed correctly!<br />
<pre>" . $sql . "</pre><br /><br />";

}

$file_id = mysql_insert_id($connection);
// File data is insterted into filedata table using while loop until end
// of tmp file is reached! Masterid should be the same for each 64k chunk!

// Opens tmp file uploaded for reading
$fp = fopen($bin_filepath, "rb"); // The b forces binary

while (!feof($fp)) {
$binarydata = addslashes(fread($fp, 65535));

$sql = "INSERT INTO filedata (masterid, filedata) VALUES ('";
$sql .= $file_id . "', '" . $binarydata . "')";


if (!mysql_query($sql, $connection)) {
die("Failure to insert binary inode data row!");
}

}

fclose($fp);



echo "<hr>";
echo "Files are: <br />";
echo "$bin_filepath <br /> $bin_filetype <br /> $bin_filename <br />";
echo "<br /><br />";
echo"File time is: $file_time<br /> File date is: $file_date<br />";
echo "<br /><br />";
echo "<hr>";

$linkid = "download_image.php?id=" . "$file_id";
echo "<a href=\"$linkid\">VIEW PICTURE</a><br />";
echo "$linkid";

?>

-----------------------------------------------------------------------------------------------------------------

download_image.php

<?php
// Download script.. streams data from a mysql database, thru the webserver to a client browser


$db = "image";

if (!$connection = mysql_connect("$db", "image", "")) {
die("Unable to connect to storage server!");
}

if (!mysql_select_db("image", $connection)) {
die("Unable to connect to storage database!");
}



$nodelist = array();

// Pull file meta-data
$sql = "SELECT * FROM file WHERE id = " . $_GET["id"];
if (!$result = mysql_query($sql, $connection)) {
die("Failure to retreive file metadata");
}

if (mysql_num_rows($result) != 1) {
die("Not a valid file id!");
}

$FileObj = mysql_fetch_object($result);

// Pull the list of file inodes
$sql = "SELECT * FROM filedata WHERE masterid = " . $_GET["id"] . " ORDER BY id";

if (!$result = mysql_query($sql, $connection)) {
die("Failure to retrive list of file inodes");
}

while ($current = mysql_fetch_object($result)) {
$nodelist[] = $current->id;
}

// Send down the header to the client
// header for datatype will display image on page but others have it download
header ( "Content-Type: $FileObj->datatype" );
header ( "Content-Name: $FileObj->name" );
// header ( "Content-Length: " . $FileObj->size );
// header ( "Content-Disposition: attachment; filename=$FileObj->name" );
//header ( "filename=$FileObj->name" );
// Loop thru and stream the nodes 1 by 1

for ($Z = 0 ; $Z < count($nodelist) ; $Z++) {
$sql = "SELECT * FROM filedata WHERE id = " . $nodelist["$Z"];

if (!$resultx = mysql_query($sql, $connection)) {
die("Failure to retreive file node data");
}

$DataObj = mysql_fetch_object($resultx);
//$DataObj->filedata;
echo $DataObj->filedata;

}
?>

-------------------------------------------------------------------------------------------------------------
sql tables

CREATE TABLE IF NOT EXISTS `file` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`datatype` varchar(60) NOT NULL DEFAULT 'application/octet-stream',
`name` varchar(120) NOT NULL DEFAULT '',
`size` bigint(20) unsigned NOT NULL DEFAULT '1024',
`filedate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;



CREATE TABLE IF NOT EXISTS `filedata` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`masterid` mediumint(8) unsigned NOT NULL DEFAULT '0',
`filedata` blob NOT NULL,
PRIMARY KEY (`id`),
KEY `master_idx` (`masterid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
willaguila
 
Posts: 1
Joined: 26. September 2009 17:21

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 117 guests