Jump to content

check and rename if file exist on upload


uberweiss

Recommended Posts

Hi.

 

I've made a script that upload to folder on my webserver

who do i check the file name and if the file exists change it.

 

for instance.

 

coc.xls exist so i want it to be named coc1.xls.. next file has to be named coc2.xls and so on.

 

and where should i put the code? im a bit of a php newbie, so thanks in advance.

 

 

i've pasted my code in:

 

<?php

 

$path = "C:\web\www-root\www.eurogiro.com\html\joomla\upload";//Sti til mappen filen skal uploades i!

$filename = "coc.xls";//Filens navn

$httproot = "";//http://www.eurogiro.com/upload/ roden til mappen som filen skal uploades til.

if(count($_POST)>0)//Der bliver postet til scriptet

{

    $file = $_FILES['file'];

   

   

   

    if(move_uploaded_file($file['tmp_name'], $path."/".$filename))

    {

        echo 'The file has been succesfully uploaded';

    }

    else

    {

        echo 'The file wasnt uploaded. Please try again';

    }

}

else

{

$form = '<form enctype="multipart/form-data" action="" method="post">

<input type="file" name="file" value=""><br>

<input type="submit" name="submit" value="Upload">

</form>';

echo $form;

}

echo "</body>

</html>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.