Hi, i m trying to build one function which the end user can upload a non extension file name for example, index.html, the end user need to delete the extension and rename it to index. this is due to integration with another system which can only read non extension file name.
[code=php]
<?
if (isset ($HTTP_POST_FILES[‘txtFile’])){
$file = $HTTP_POST_FILES[‘txtFile’];
if ($file[‘size’] > 0) {
if (!is_uploaded_file($file[‘tmp_name’])) {
echo “<script languague = ‘JavaScript’>”;
echo “alert(‘Not an authentic file!’)”;
echo “</script>”;
}
// the number of bytes to read from the file
$bytelen = $file[‘size’];
// file pointer to the temporary location of the
// uploaded file
$fp = fopen($file[‘tmp_name’], ‘r’);
// read in the file data and close the pointer
$data = fread($fp, $bytelen);
fclose($fp);
$name = $file[‘name’];
$extension = strtolower(substr($name, -4));
$newname = “test”;
$file[‘name’] = $newname;
$file = $_FILES[‘txtFile’][‘name’];
if ($extension == “”){
$uploaddir = ‘upload/’;
$uploadfile = $uploaddir . $newname;
if (move_uploaded_file($HTTP_POST_FILES[‘txtFile’][‘tmp_name’], $uploadfile)) {
echo “correct”;
}
}else{
echo “<script languague = ‘JavaScript’>”;
echo “alert(‘not uploaded! Please upload again!’)”;
echo “</script>”;
}
}
}?>
<form enctype=”multipart/form-data” method=”post” name=”upload”>
<input type=”text” name=”txtDir”>
<table width=”100%” border=”0″ cellspacing=”1″ cellpadding=”2″>
<tr>
<td class=”small” width=”20%”>Upload <input name=”txtFILE” type=”file” onchange = “document.upload.txtDir.value = this.value” ></td>
<td><input type=”submit” name=”Upload” value=”Upload”></td>
</tr>
<td></td>
</tr>
</table>
</form>
What’s wrong with the code? and how come it is not working?