Document Management in PHP - URGENT HELP NEEDED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dream2rule
Forum Contributor
Posts: 109
Joined: Wed Jun 13, 2007 5:07 am

Document Management in PHP - URGENT HELP NEEDED

Post by dream2rule »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php

if(isset($_POST['submit']))
{
	
	//retrieving form values
	$student_id = $_POST['student_id'];
	echo $student_id;
	
	if(empty($student_id))
		exit("ERROR: The Student ID field cannot be empty. Please select an ID.");
	
	$dir = "documents/";
	mkdir($dir,0777);
	
	
	foreach($_FILES["prev_school_doc"]["error"] as $key => $error)
	{	
		if (is_uploaded_file($_FILES['prev_school_doc']['tmp_name'])) 
		{
			if ($error == UPLOAD_ERR_OK) 
			{
        		$tmp_path = $_FILES["prev_school_doc"]["tmp_name"][$key];
        	
				$name = $_FILES["prev_school_doc"]["name"][$key];
			
				$dest_path = "$dir"."previous_school_documents/".$name;
        	
				move_uploaded_file($tmp_path, $dest_path);
			}
		}
	}
}

?>

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style2 {
	color: #000000;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: large;
}
-->
</style>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table cellpadding="0" cellspacing="0" border="1" align="center" width="70%">
<tr><td>
	
	<table width="100%" border="0" align="center">
    	<tr>
      		<td height="43" colspan="3" bgcolor="#CCCCCC"><span class="style2">Document Management</span></td>
    	</tr>
    	<tr>
      		<td width="28%"><br />
   		    ID Number:</td>
      		<td colspan="2"><label><br />
			<select name="student_id" id="student_id">
			<option value="" selected="selected"> [ Select Student ID ] </option>
			<option value="1">1</option>
        	<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			</select>
      		</label></td>
    	</tr>
    	<tr>
      		<td height="48">Previous School Document: </td>
      		<td width="48%"><label><input name="prev_school_doc[]" type="file" size="40" /></label></td>
      		<td width="24%" align="center"><a href="<? $PHP_SELF; ?>">Add another file </a></td>
    	</tr>
    	<tr>
      		<td height="36">Medical Reports: </td>
      		<td><label><input name="medical_reports[]" type="file" size="40" /></label></td>
      		<td align="center"><a href="<? $PHP_SELF; ?>">Add another file</a> </td>
    	</tr>
    	<tr>
      		<td height="35">Immunization Card: </td>
      		<td colspan="2"><label><input name="immunization_card" type="file" size="40" /></label></td>
   		  </tr>
    	<tr>
      		<td height="31">Family Agreement: </td>
			<td colspan="2"><label><input name="family_agreement" type="file" size="40" /></label></td>
      	</tr>
    	<tr>
      		<td height="27" colspan="3">Filming, Photographing, Videotape & Release Pictures Document:
      		<label></label></td>
    	</tr>
    	<tr>
      		<td height="32" colspan="2" align="right"><label><input name="filming_doc" type="file" size="40" />
      		</label></td>
      		<td>&nbsp;</td>
    	</tr>
    	<tr>
			<td height="31">Excursion Document:</td>
      		<td><label><input name="excursion_doc" type="file" size="40" /></label></td>
      		<td>&nbsp;</td>
    	</tr>
    	<tr>
      		<td height="29" colspan="3">Consent for Hydrotherapy and Swimming: </td>
    	</tr>
    	<tr>
      		<td height="33" colspan="2" align="right"><label>
      		  <input name="hydro_swim_doc" type="file" size="40" /></label></td>
      		<td>&nbsp;</td>
    	</tr>
    	<tr>
      		<td height="33">Consent for Immunization: </td>
		    <td><label>
		    <input name="immunizaion_doc" type="file" size="40" />
		    </label></td>
      		<td>&nbsp;</td>
    	</tr>
    	<tr>
      		<td height="29" colspan="3">Medical History & Treatment Approval Form: </td>
    	</tr>
    	<tr>
     		<td height="26" colspan="2" align="right"><label><input name="med_history_doc" type="file" size="40" /></label></td>
      		<td>&nbsp;</td>
    	</tr>
    	<tr>
      		<td height="55" colspan="3" align="center"><label><input type="submit" name="submit" value="Submit" /></label></td>
    	</tr>
  	</table>
  
</td></tr></table>
</form>
</body>
</html>
Here, in the above PHP code i need to check for the various files uploaded. I am unable to go about it..

I have 9-10 files to be uploaded. How do i retrieve the files and then insert their respective paths into the database?

And each file uploaded should be stored in a respective folder like if its a medical report then the file must be stored as /documents/medical_reports/file_name.(Documents folder being the root to store all the uploaded files and medical_reports being a sub-folder in the documents folder)

The mkdir() function i have used always gives out an error saying the file already exists!

Any help?

Regards,
Dream2rule


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
rustem
Forum Newbie
Posts: 9
Joined: Tue Jun 26, 2007 2:41 am

Post by rustem »

$dir = "documents/";
Have you tried without "/", just "documents" ?
Also, before you make a directory, check whether it already exists:

Code: Select all

if(!is_dir($dir)){
    mkdir($dir);
}
What touches saving filepaths into DB, why don't you want to save them during the upload?

If for some reason you want to do it later, read documentation for opendir() function.
dream2rule
Forum Contributor
Posts: 109
Joined: Wed Jun 13, 2007 5:07 am

Post by dream2rule »

yes.. i mean that as soon as i submit the form or as soon as they are uploaded the paths of the respective files should be uploaded into the database.
dream2rule
Forum Contributor
Posts: 109
Joined: Wed Jun 13, 2007 5:07 am

Post by dream2rule »

thanks rustem, the mkdir() logic worked...

Now how do i go about the upload files logic??

any ways to do it??

Regards
Post Reply