Return to Snippet

Revision: 1103
at September 9, 2006 16:52 by smilylion


Initial Code
<?php
// Usage: uploadfile($_FILE['file']['name'],'temp/',$_FILE['file']['tmp_name'])
function uploadfile($origin, $dest, $tmp_name)
{
  $origin = strtolower(basename($origin));
  $fulldest = $dest.$origin;
  $filename = $origin;
  for ($i=1; file_exists($fulldest); $i++)
  {
   $fileext = (strpos($origin,'.')===false?'':'.'.substr(strrchr($origin, "."), 1));
   $filename = substr($origin, 0, strlen($origin)-strlen($fileext)).'['.$i.']'.$fileext;
   $fulldest = $dest.$newfilename;
  }
 
  if (move_uploaded_file($tmp_name, $fulldest))
   return $filename;
  return false;
}
?>

Initial URL


Initial Description


Initial Title
upload php auto rename

Initial Tags


Initial Language
PHP