Commonly used PHP code examples for uploading files in dynamic website development.
Webpage Teaching Network (webjx.com) file upload example
";
";
function getname($exname){
$dir = "../PreviousFile/";
$i=1;
if(!is_dir($dir)){
mkdir($dir,0777);
}
while(true){
if(!is_file($dir.$i.".".$exname)){
$name=$i.".".$exname;
break;
}
$i++;
}
return $dir.$name;
}
$exname=strtolower(substr($_FILES[upfile][name],(strrpos($_FILES[upfile][name],.)+1)));
$PreviousFile = getname($exname);
if (move_uploaded_file($_FILES[upfile][tmp_name], $PreviousFile)) {
echo "
File uploaded successfully!
";
}else {
echo "
File upload failed!
";
}
echo "The following is some information about file upload:
Original file name: ".$_FILES[upfile][name] .
"
Type:" .$_FILES[upfile][type] .
"
Temporary file name: ".$_FILES[upfile][tmp_name].
"
File size:".$_FILES[upfile][size] .
"
Error code:".$_FILES[upfile][error];
?>