Rename af fil ved upload
Jeg har et script som uploader en pdf-fil. Jeg vil have renamet min "inputfil" til at hedde det samme uanset, hvad navnet var i forvejen.-alle de filer, der uploades skal hedde arkiv.pdf - selvom der ligger en med samme navn, der så bliver overskrevet.
Min kode:
<?php
@$upload_Name = $_FILES['upload']['name'];
@$upload_Size = $_FILES['upload']['size'];
@$upload_Temp = $_FILES['upload']['tmp_name'];
@$upload_Mime_Type = $_FILES['upload']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
// Validation
if( $upload_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Husk at skrive filnavn</font></p>");
}
if( $upload_Size >2000000)
{
//delete file
unlink($upload_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Storrelse paa fil er for stor</font></p>");
}
if( $upload_Mime_Type != "application/msword" AND $upload_Mime_Type != "application/pdf" AND $upload_Mime_Type != "application/rtf" )
{
unlink($upload_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Kun PDF-filer kan uploades</font></p>");
}
$uploadFile = "uploadspdf/".$upload_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $upload_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload_URL = "http://localhost/uploadspdf".$upload_Name ;
echo "Fil er uploaded";
?>
Hvordan - og hvor skal jeg foretage mig den handling?
