0

Dears
I have Developed a System for UPLOAD PDF files in Database.
I Require to rename the file as LA when file is Uploaded in DB.

Here is my Form

<form enctype="multipart/form-data" action="dS.php" method="POST">
  <tr>
    <td><table width="98%" border="0" cellspacing="0" cellpadding="0" >
	<span class="style7 style1">Site Id</span><input type="text" name="id" value="" />
	
  <tr>
    <td width="39%"><div align="right"><span class="style7 style1">Upload LA:</span></div></td>
    <td width="61%"><!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="9999999" />
	
    <!-- Name of input element determines name in $_FILES array -->
     <input name="userfile" type="file"  /><br /></td>
  </tr>

  <tr>
    <td colspan="2" align="center"><input type="hidden" id="b" name="pa"  /></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" value="" /> </td>
    </tr>
   
</table>
</td>
  </tr>
  </form>

and here is mu Upload file code

<?php

	$id=$_POST['id'];
	
	$path = $_SERVER['DOCUMENT_ROOT'] . '/LAPO/SOUTH/'.$id;

	


$filename = $path;

if (file_exists($filename)) {

	$uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/LAPO/SOUTH/$id/";

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$uploaddir1 = $_SERVER['DOCUMENT_ROOT'] . "/LAPO/SOUTH/$id/";
$uploadfile1 = $uploaddir1 . basename($_FILES['userfile1']['name']);
$uploaddir2 = $_SERVER['DOCUMENT_ROOT'] . "/LAPO/SOUTH/$id/";
$uploadfile2 = $uploaddir2 . basename($_FILES['userfile2']['name']);
 $extension= end(explode(".", $uploadfile));
  $extension1= end(explode(".", $uploadfile1));
   $extension2= end(explode(".", $uploadfile2));
   
   	if ($extension!= "pdf")
	{
	echo "<b>ERROR:File Format Of Lease Agreement is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File</b></a>";
	
	
		if ($extension1!= "pdf")
		{
		echo "<b>ERROR:File Format of PO is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File</b></a>";
		
				if ($extension2!= "pdf")
				{
				echo "<b>ERROR:File Format of SPA is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File</b></a>";
				}

				print "</pre>";
				echo '<pre>';
				if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
   				 echo "SPA Successfully uploaded.\n";
				} 
		}
		else
		{
			print "</pre>";
			echo '<pre>';
			if (move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1)) {
   		 	echo "Purchase Order Successfully uploaded.\n";
			} else {
   	 		echo "Purchase Order file Path is invalid!\n";
			}
			if ($extension2!= "pdf")
				{
				echo "<b>ERROR:File Format of SPA is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File</b></a>";
				}

				print "</pre>";
				echo '<pre>';
				if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
   				 echo "SPA Successfully uploaded.\n";
				} 
		}

	
	
	}
 	else
	{
		echo '<pre>';
		if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    	echo "Lease Agreement Successfully uploaded.\n";
		} else {
   		 echo "Lease Agreement file Path is invalid!\n";
		}
	if ($extension1!= "pdf")
		{
		echo "<b>ERROR:File Format of PO is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File \n</b></a>";
		
				if ($extension2!= "pdf")
				{
				echo "<b>ERROR:File Format of SPA is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File \n</b></a>";
				}

				print "</pre>";
				echo '<pre>';
				if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
   				 echo "SPA Successfully uploaded.\n";
				} 
		}
		else
		{
			print "</pre>";
			echo '<pre>';
			if (move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1)) {
   		 	echo "Purchase Order Successfully uploaded.\n";
			} else {
   	 		echo "Purchase Order file Path is invalid!\n";
			}
			if ($extension2!= "pdf")
				{
				echo "<b>ERROR:File Format of SPA is not Supported, Please Select A PDF File</b><a style=color:#FF0000; href=sendfileS.php><b>-Select Another File</b></a>";
				}

				print "</pre>";
				echo '<pre>';
				if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
   				 echo "SPA Successfully uploaded.\n";
				} 
		}	
		
	}

/*echo 'Here is some more debugging info:';
print_r($_FILES);*/



print "</pre>";
} ?>
2
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by ayesha789
0

if user file name is abc987.pdf when he/she Uploads it will save as LA.pdf
In my case user have to change the file name as LA.pdf before UPloadng. I want to make my application userfriendly.

0

In move_uploaded_file.
Replace $uploadfile2 in:

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)

with a file name that you want.Example:

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploaddir2."file.pdf")

Edited by web3: n/a

0

You see in the above example that the second part in move_uploaded_file is upload directory with the file name.

0

In move_uploaded_file.
Replace $uploadfile2 in:

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)

with a file name that you want.Example:

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploaddir2."file.pdf")

No dear
I chage as

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploaddir2."LA.pdf")

it saving as
4862.pdfLA and name of file is 4862.pdf
I want to change completely as LA.pdf

0

mt this code

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

showing this path

C:/xampp/htdocs/LAPO/SOUTH/0000/[B]4862.pdf[/B]

I want to change 4862 with LA
like

C:/xampp/htdocs/LAPO/SOUTH/0000/[B]LA.pdf[/B]
0

Did you put this on all the places?

move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploaddir2."LA.pdf")

How it doesn't work?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.