php如何将上传的files图片文件转为jpg?
php如何将上传的files图片文件转为jpg?
上传文件时会在服务器生成一个temp文件,正常的上传文件流程就是你要去取这个temp文件,然后再写入。
然后就是在你写入的地方,给写上.jpg即可。
<code>// 获取临时文件
$tempFile = $_FILES[$field]['tmp_name'];
if($tempFile){
$uploadDir = 'static/upload';
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0777);
}
// 在这里重新写入文件,包括后缀
$targetFile = $uploadDir . '/' . time() . '.jpg';
move_uploaded_file($tempFile, $targetFile);
$this->model->$field = $targetFile;
}</code>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号