php 上传图片改名 修改第7行$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['userfile']['name']; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $targetFile = $targetPath . '/' . $user . '.' . pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION); <?php $user="hah";$targetFolder = '/uploads'; // Relative to the rootif (!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.'; }}?> 请教windows下配置php的memcache的问题 如何更新PHP批量生成的静态页面 php程序执行过程中显示一张图片3秒钟 怎么防止用户非法登陆 如何格式化一个字符串? 如何去除字符串中非汉字、非字母、非数字的字符? 求助:copy()函数的问题. 如何对phpmyadmin目录进行保护??????? 大家一起来分析,说不定能提高你PHP的水平哦! linux安装 apache php 无法解析 将转PHP的新手,有没有什么好书推荐? 请教下php的Resource问题?
$targetFolder = '/uploads'; // Relative to the rootif (!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.';
}
}?>