Jump to content

[SOLVED] problem to upload.php


Hany_h2004

Recommended Posts

Sql

----------

CREATE  TABLE  `files` ( `id` INT UNSIGNED NOT  NULL  AUTO_INCREMENT ,

`filename` VARCHAR( 255  )  NOT  NULL ,

`filesize` INT NOT  NULL ,

`filetype` VARCHAR( 255  )  NOT  NULL ,

`filedata` BLOB NOT  NULL ,

PRIMARY  KEY (  `id`  )

);

----------

.html

 

-------

<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="text" name="filename" /><br />
<input type="file" name="filedata" /><br />
<input type="submit" name="submit" value="submit" /><br />
</form> 

-----------

 

 

config.php

----------

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
?> 

---------

 

files.php

-------

<?php
include_once('config.php');
$query="SELECT id,filename,filesize,filetype FROM files";
$result=mysql_query($query) or die(mysql_error());
$table='';
while($rows=mysql_fetch_row($result)){
$table.="<tr><td>$rows[1]<td>$rows[2]</td><td><a href='download.php?id=$rows[0]'>Download</a></td></tr>";
}
?>
<html>
<head>
<title>Files</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table border="1">
<tr>
<td>FileName</td><td>FileSize</td><td>DownLoad</td>
</tr>
<?= $table;?>
</table>
</body>
</html> 

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

 

download.php

----------

<?
mysql_connect("localhost", "root", "");
mysql_select_db("dbname");

if($_FILES['filedata']['tmp_name'] != "")
{
    $fileName = $_FILES['filedata']['name'];
    $tmpName  = $_FILES['filedata']['tmp_name'];
    $fileSize = $_FILES['filedata']['size'];
    $fileType = $_FILES['filedata']['type'];
    $fo = @fopen($tmpName, "r");
    $data = @fread($fo, filesize($tmpName));
    $data = addslashes($data);
}
$result = @mysql_query("INSERT INTO `files` VALUES ('', '$fileName', '$fileSize', '$fileType', '$data')");
if($result)
{
    echo "right";
}
else
{
    echo "wrong";
}

?> 

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

 

the problem

 

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\local_hany\up\config.php:4) in C:\AppServ\www\local_hany\up\download.php on line 23

 

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\local_hany\up\config.php:4) in C:\AppServ\www\local_hany\up\download.php on line 24

 

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\local_hany\up\config.php:4) in C:\AppServ\www\local_hany\up\download.php on line 25

 

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/142969-solved-problem-to-uploadphp/
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.