PHP code to upload files_PHP tutorial

WBOY
Release: 2016-07-13 17:29:32
Original
792 people have browsed it

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];
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531665.htmlTechArticleCommonly used PHP code examples for uploading files in dynamic website development. html head meta http-equiv="Content-Type" content="text/html; charset=gb2312" title Web page teaching network (webjx.com) file...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template