Jump to content

How to upload file to server


9911782

Recommended Posts

Hi All

I'm new in PhP & Mysql.

I want to upload a file(word document, excel, pfd) to a website. So, I would like my users to be able to get the url to that file and be able to download the file or save the file.

I have written this code for uploading:

<?php session_start();?>
<?php
//If (empty($_SESSION['svarticleid'])) {
// header("Location: login.php");
//}
?>
<?php
//open connection to the database
require_once('inc_conn.php');
// prepare query
//$sql="SELECT emdc.emdcno, policies.emdcno FROM policies, emdc WHERE policies.emdcno = emdc.emdcno AND emdc.emdcname = '".$emdcname."'";
$sql="SELECT emdcno, emdcname FROM emdc;";
//execute sql statements
$rsemdcno = mysql_query($sql, $connimgp) or die(mysql_error());
//retrieve one row of records
$rows_rsemdcno = mysql_fetch_array($rsemdcno);
//determine the number of records in recordset
$num_rows = mysql_num_rows($rsemdcno);
?>
<?php
//check if button clicked
if (isset($_POST['btnsubmit'])) {
//Grab form variables and assign to the user defined variables
$articletitle=$_POST["title"];
$articledescrip=$_POST["discription"];
$articleurl=$_POST["userfile"];
$emdcno=$_POST["emdc"];
$date=date("Y-m-d");
//Open connection
require_once('inc_conn.php');
//insert into the database
$insertSQL ="INSERT INTO articlesresearch(articleid, articletitle, articledescrip, articleurl, emdcno, sdatetime) VALUES ('$articleid', '$articletitle', '$articledescrip', '$articleurl', '$emdcno', '$date')";
//execute the insert statement
$execute = mysql_query($insertSQL, $connimgp) or die(mysql_error());
//redirect to viewarticles
If ($execute) {
mysql_close($connimgp);
header("Location: viewarticle.php");
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
<table width="720" height="600" border="1" cellpadding="2" cellspacing="0">
<?php require_once("inc_header.php");?>
<tr>
<?php require_once("inc_menu.php");?>
<td width="536" height="300" valign="top">
<?php require_once("inc_adminmenu.php");?>
<p class="headings" align="center">[Articles and Research] </p>
<form name="form1" method="post" action="">
<table width="536" border="0" cellspacing="0" cellpadding="2">
<?php // if (isset($_REQUEST["signin"])){?>
<tr>
<td colspan="2"><p align="center">You need to logged in!<br>
Login</p>
</td>
</tr>
<?php // }?>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="156"><div align="right">Title</div></td>
<td width="366"><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td><div align="right">Description</div></td>
<td> <textarea name="discription" id="discription"></textarea></td></tr>
<tr>
<td><div align="right">Url</div></td>
<td><input name="userfile" type="file"></td>
</tr>
<tr>
<td><div align="right">EMDC</div></td>
<td> <select name="emdcno">
<option value="">Select Emdc</option>
<?php do { ?>
<option value=""><?php echo $rows_rsemdcno['emdcno']; ?></option>
<?php } while ($rows_rsemdcno = mysql_fetch_array($rsemdcno)); ?>
</select></td>
</tr>
<tr>
<td><div align="right">Date</div></td>
<td><input name="date" type="text" id="date"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="btnsubmit" type="submit" id="btnsubmit" value="Submit"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<p>&nbsp;</p></td>
</tr>
<?php require_once("inc_footer.php");?>
</table>
</body>
</html>
<?php
//free results of recordset
mysql_free_result($rsemdcno);
//Close conn
mysql_close($connimgp);
?>
---------------------------------------------------
I have written this file for viewing all my uploads, but now I dont now how to call that url(file) to be able to view/download/save it.

here is the code to view uploads:

<?php session_start();?>
<?php
//connect to MySQL server and imgp
require_once('inc_conn.php');
//execute sql
$sql="select * from articlesresearch";
//execute sql statements
$rsarticle = mysql_query($sql, $connimgp) or die(mysql_error());
//retrieve one row of records
$rows_rsarticle = mysql_fetch_array($rsarticle);
//determine the number of records in recordset
$num_rows = mysql_num_rows($rsarticle);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<table width="720" height="600" border="1" cellpadding="2" cellspacing="0">
<?php require_once("inc_header.php");?>
<tr>
<?php require_once("inc_menu.php");?>
<td width="536" height="300" valign="top">
<?php require_once("inc_adminmenu.php");?>
<p class="headings" align="center">[Articles and Research] </p>
<div style="overflow:auto;height:200px;margin:0px;">
<table width="536" border="1" bordercolor="" cellspacing="0" cellpadding="3">
<tr>
<td width="184">Title</td>
<td width="170">Discription</td>
<td width="75">Date</td>
<td width="77">&nbsp;</td>
</tr>
<?php do{ ?>
<tr>
<td><?php echo $rows_rsarticle['articletitle'];?></td>
<td><?php echo $rows_rsarticle['articledescrip'];?></td>
<td><?php echo $rows_rsarticle['sdatetime'];?></td>
<td><a href="#" onClick="window.open('<?php echo $rows_rsarticle['articleurl'];?>', '', 'width=400,height=250,top=10,left=10,scroll=no,resize=no')">View</a></div></td>
</tr>
<?php }while($rows_rsarticle = mysql_fetch_array($rsarticle));?>
</table>
</div>
<p><a href="addarticle.php">Add New Articles and Research</a> </p></td>
</tr>
<?php require_once("inc_footer.php");?>
</table>
</body>
</html>
<?php
//free results of recordset
mysql_free_result($rsarticle);
//Close conn
mysql_close($connimgp);
?>
------------------------------------------

can you ps help me on this.

thank
S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.