Jump to content

PHP UPLOAD & DISPLAY


RCS

Recommended Posts

Hi everyone, I'm trying to create a script where I can save form data e.g Make, Description, Price, Picture

after saving data to mysql I want to post it by id to a catalog page. I'm having an issue with getting image from database.

I can't seem to figure it out. If someone could help me it would be greatly appreciated.

Thank you very much in advance.

 

This is form

<html>

<body><form action="upload_file.php" method="POST"

enctype="multipart/form-data">

<p><label for="file">Filename:</label>

<input type="file" name="file" id="file" />

<input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"></p>

<p><label><b>Make:</b></label>

<input type="text" name="make" id="make" /></p>

<p><label><b>Price:</b></label>

<input type="text" name="price" id="price" /></p>

<p><label><b>Category:</b></label>

<input type="text" name="category" id="category" /></p>

<p><label><b>Description:</b></label>

<textarea name="description" id="description" cols="45" rows="5"></textarea /></p>

<br />

<input type="submit" name="submit" value="Submit" />

</form></body>

</html>

 

This is upload page where everything gets saved to database

<?php

include("dbinfo.inc");

include("file_array.inc");

if(isset($_POST['upload']) && $_FILES['file']['size'] > 0)

{

$fp      = fopen($tmpName, 'r');

$content = fread($fp, filesize($tmpName));

$content = addslashes($content);

fclose($fp);

if(!get_magic_quotes_gpc())

{

    $fileName = addslashes($fileName);

}

}

$con = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);

$query = "INSERT INTO upload(name, size, type, content, make, price, description)".

"VALUES ('$fileName', '$fileSize', '$fileType', '$content','$_POST[make]','$_POST[price]','$_POST[description]')";

$result=mysqli_query($con, $query) or die ("Could not complete query.");

mysql_close($con);

?>

<html>

<head><title>CMS</title></head>

<body><center><b>Information successfuly saved to database.</b></center></body>

</html>

 

This is page where data gets posted

<html>

<head>

<title>Download File From MySQL</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

include("dbinfo.inc");

$con = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);

$query = ("SELECT * FROM upload ORDER BY id");

$result = mysqli_query($con, $query) or die('Error, query failed');

echo "<table border='1'>

<tr>

<th>Make</th>

<th>Description</th>

<th>Price</th>

<th>Picture</th>

</tr>";

while($row = mysqli_fetch_array ($result))

  {

  echo "<tr>";

  echo "<td>" . $row['make'] . "</td>";

  echo "<td>" . $row['description'] . "</td>";

  echo "<td>" . $row['price'] . "</td>";

  echo "<td>" . $row['name'] . "</td>";

  echo "</tr>";

  }

echo "</table>";mysqli_close($con);

?>

<a href="download.php?id=<?php echo $id; ?>"><?php echo $name;?></a><br>

<?php

mysql_close($con);

?>

</body>

</html>

 

This is file_array

<?php

$fileName = $_FILES['file']['name'];

$tmpName  = $_FILES['file']['tmpName'];

$fileSize = $_FILES['file']['size'];

$fileType = $_FILES['file']['type'];

?>

 

Don't laugh to hard!!

;D

Link to comment
https://forums.phpfreaks.com/topic/98760-php-upload-display/
Share on other sites

Well my database is like this

 

CREATE TABLE upload (

id INT NOT NULL AUTO_INCREMENT,

name VARCHAR(30) NOT NULL,

type VARCHAR(30) NOT NULL,

size INT NOT NULL,

description VARCHAR(350) NOT NULL,

price VARCHAR(128) NOT NULL,

make VARCHAR(30) NOT NULL,

category VARCHAR(30) NOT NULL,

content MEDIUMBLOB NOT NULL,

PRIMARY KEY(id)

);

ok,

 

Have I got the wrong end of this stick?

 

when you say getting an image from the database, what are you expecting to see?

 

Well my database is like this

 

CREATE TABLE upload (

id INT NOT NULL AUTO_INCREMENT,

name VARCHAR(30) NOT NULL,

type VARCHAR(30) NOT NULL,

size INT NOT NULL,

description VARCHAR(350) NOT NULL,

price VARCHAR(128) NOT NULL,

make VARCHAR(30) NOT NULL,

category VARCHAR(30) NOT NULL,

content MEDIUMBLOB NOT NULL,

PRIMARY KEY(id)

);

do I have to some how save the file to a location and not the database??

I just don't understand ???????????????????????

It seems to save the file info to database so wouldn't that mean that file is saved.

If so how do I display it with the other info e.g make, description, price

??????????????????????????????????????????????????????????????

 

hmm, im lost on this one, im only a bit of a novice really, but sometimes a pair of fresh eyes see's it straight away, I think this is over my head :(

 

Sorry i couldnt help you more :(

 

I do I have to some how save the file to a location and not the database??

I just don't understand ???????????????????????

It seems to save the file info to database so wouldn't that mean that file is saved.

If so how do I display it with the other info e.g make, description, price

??????????????????????????????????????????????????????????????

 

<?php

/**

* Keith Maki, RCS

*/

?>

<html>

<head>

<title>Download File From MySQL</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

include("dbstuff.inc");

$con = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);

$query = ("SELECT * FROM upload ORDER BY id");

$result = mysqli_query($con, $query) or die('Error, query failed');

echo "<table border='1'>

<tr>

<th>Make</th>

<th>Description</th>

<th>Price</th>

<th>Picture</th>

</tr>";

while($row = mysqli_fetch_array ($result))

  {

  echo "<tr>";

  echo "<td>" . $row['make'] . "</td>";

  echo "<td>" . $row['description'] . "</td>";

  echo "<td>" . $row['price'] . "</td>";

  echo "<td><img src='http://www.refinedcomputersolutions.com/php_scripts/tmpName/'" . $row['name'] . "</td>";

  echo "</tr>";

   }

echo "</table>";mysqli_close($con);

?>

<a href="download.php?id=<?php echo $id; ?>"><?php echo $name;?></a><br>

<?php

mysql_close($con);

?>

</body>

</html>

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.