shaileshpatil
11-18-2006, 12:21 PM
Hi
upload.php
<?
// Where the file is going to be placed
$target_path = "../files/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
upload.html
<form enctype="multipart/form-data" name="form1" action="upload.php" method="POST">
<table cellpadding=1 cellspacing=3 class="table" width="60%" border=0>
<tr>
<td class="r" width="30%">Choose a file to upload: </td>
<td ><input name="uploadedfile" type="file"></td>
</tr>
<tr>
<td class="r" colspan="2" align="center"><input type="submit" value="Upload File"></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
</table>
</form>
This scripts works absolutely fine. It uploads the file to specific directories.
While uploading i want to rename a file with same extension it has. The purpose of doing so, is to avoid files being overwritten.
Any suggestions
upload.php
<?
// Where the file is going to be placed
$target_path = "../files/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
upload.html
<form enctype="multipart/form-data" name="form1" action="upload.php" method="POST">
<table cellpadding=1 cellspacing=3 class="table" width="60%" border=0>
<tr>
<td class="r" width="30%">Choose a file to upload: </td>
<td ><input name="uploadedfile" type="file"></td>
</tr>
<tr>
<td class="r" colspan="2" align="center"><input type="submit" value="Upload File"></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
</table>
</form>
This scripts works absolutely fine. It uploads the file to specific directories.
While uploading i want to rename a file with same extension it has. The purpose of doing so, is to avoid files being overwritten.
Any suggestions