TEDIA会員に登録したメールアドレスとパスワードを入力してください

メールアドレス:

     パスワード:


パスワードを忘れた方はパスワードの確認を行ってください。

TEDIA会員へのご登録がお済みで無い方はこちらで登録ができます


>> テクノロジーポータル TEDIA トップページへ戻る <<

Think IT Software Developer's Think IT Find-IT 失敗しないソフト選び Find-IT TEDIA テクノロジーポータル TEDIA インストールマニアックス2008 インストールマニアックス2008

TEDIA SponsorsOpen Source Web Development Tutorials - Dev Shed

プロジェクト管理アプリケーションのファイル処理
(2008/12/25公開)

プロジェクト管理アプリケーションのファイル処理

 今回は、プロジェクトに必要なファイルを処理する方法を学習しましょう。標準PHPファンクションを使ってファイルをアップロードする方法も解説します。このシリーズはプロジェクト管理アプリケーションの構築を7回に分けて解説するチュートリアルですが、今日はいよいよ第6回です。最終回の第7回まで頑張ってください。

 さて、最初に取り上げるのは、プロジェクトに使用する全部のファイルを一覧表示するview_files.phpスクリプトです。ユーザーがファイルをアップロードすると、ファイルの名前とプロジェクトIDがデータベースに格納されます。物理ファイルは'p_files'フォルダーに格納されます。

 スクリプト全体のコードは、以下のとおりです。


<?php 
include "dbcon.php"; 
include "functions.php"; 

if(isset($_GET['pid'])){ 
//clean pid 
if(!is_numeric($_GET['pid'])){ 
//the value received is not numeric. redirect the user to login 
header("location:login.php"); 


//otherwise clean the received value for query use 

$cpid = mysql_escape_string($_GET['pid']); 

//get project name 

$getname = "SELECT title FROM projects WHERE pid = '".$cpid."'"; 
$g_result = mysql_query($getname); 
if(!$g_result){ 
echo mysql_error() 
}else{ 
$rowname = mysql_fetch_assoc($g_result); 
$title = $row['title']; 

//get the files 
$getfiles="SELECT * FROM files WHERE p_id = '".$cpid."' ORDER BY fid"; 
$result = mysql_query($getfiles); 
if(!$result){ 
echo mysql_error(); 
}else{ 
$num=mysql_num_rows($result); 


?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- InstanceBegin template="/Templates/PM_Main.dwt.php" 
codeOutsideHTMLIsLocked="false" --> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<!-- InstanceBeginEditable name="doctitle" --> 
<title>Untitled Document</title> 
<!-- InstanceEndEditable --> 
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> 
<link href="Templates/main.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
<table width="100%" border="0"> 
<tr> 
<td width="33%">&nbsp;</td> 
<td width="28%">&nbsp;</td> 
<td width="39%">Logged in: <!-- InstanceBeginEditable name="login" -->
<? echo $_SESSION['name'];?> | <a href="logout.php">
Logout</a><!-- InstanceEndEditable --></td> 
</tr> 
<tr> 
<td colspan="3" bgcolor="#6699CC" class="headertxt">
Project Management Software </td> 
</tr> 
<tr> 
<td colspan="3"><!-- InstanceBeginEditable name="main" --> 
<table width="99%" border="0"> 
<tr> 
<td colspan="2" class="loginheader"><?php echo $title;?> </td> 
</tr> 
<tr> 
<td>Files used by this project: </td> 
<td>&nbsp;</td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
</tr> 
<tr> 
<td><strong>File Name</strong></td> 
<td><strong>Action</strong></td> 
</tr> 
<?php 
if($num > 0){ 
while($row = mysql_fetch_assoc($result)){?> 
<tr> 
<td><?php echo $row['filename']?> </td> 
<td><a href="delete_file.php?fid=<?php echo $row['fid']?> 
& cpid=<?php echo $cpid?> ">Delete</a></td> 
</tr> 
<?php 

}else{ 
?> 
<tr> 
<td colspan="2"><p>There are no files uploaded for this project.</p></td> 
</tr> 
<?php } 
  
?> 
</table> 
<!-- InstanceEndEditable --></td> 
</tr> 
<tr> 
<td colspan="3"><!-- InstanceBeginEditable name="nav" -->
<a href="main.php">View Project List</a> | 
<a href="admin/login.php">Administrators Corner </a>
<!-- InstanceEndEditable --></td> 
</tr> 
<tr> 
<td align="right" class="cright" colspan="3">copyright &copy; 2007 PM </td> 
</tr> 
</table> 
</body> 
<!-- InstanceEnd --></html> 


1    2    3    4    次のページ

Copyright © 2008 Ziff Davis Enterprise, Inc.
Originally appearing in the U.S. Edition of Dev Shed. All Rights Reserved.