How to convert uploaded files image files to jpg in PHP?
How to convert uploaded files image files to jpg in PHP?
When uploading a file, a temp file will be generated on the server. The normal file upload process is that you need to get the temp file and then write it.
Then just write .jpg where you want to write it.
<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>