时间:2021-07-01 10:21:17 帮助过:17人阅读
$user="hah";
$targetFolder = '/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['userfile']['tmp_name']; //
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['userfile']['name'];
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['userfile']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
$arr = getimagesize($tempFile);
move_uploaded_file( $tempFile,$targetFile);
$data = array(
"state" => '00',
"desc" => 'ok',
"src" => "http://localhost/uploads/".$_FILES['userfile']['name'],
"touxiang" => $touxiangs,
);
echo json_encode($data);
} else {
echo 'Invalid file type.';
}
}
$user="hah";
$targetFolder = '/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['userfile']['tmp_name']; //
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['userfile']['name']);
$targetFile = rtrim($targetPath,'/') . '/' . $user . '.' .$fileParts['extension'];
if (in_array($fileParts['extension'],$fileTypes)) {
$arr = getimagesize($tempFile);
move_uploaded_file( $tempFile,$targetFile);
$data = array(
"state" => '00',
"desc" => 'ok',
"src" => "http://localhost/uploads/".$user . '.' .$fileParts['extension'],
"touxiang" => $touxiangs,
);
echo json_encode($data);
} else {
echo 'Invalid file type.';
}
}
?>