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.'; }}?> 求救:关于PHP的SSH2 关于回复留言弹出框的问题 小妹求救啊!多文件上传,怎么样从数组中取出数据。 sql中"和&的字符问题 求一个WEB开发入门教程 如何用dreamwave 制作utf8 内码的网页! 以及一些问题 如何用php批量管理服务器的文件和文件夹 关于用php发传真的问题(高手请进) phpmyadmin后台显示空白,查看源码都有,就是前台不显示 求教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.';
}
}?>