Home > Backend Development > PHP Tutorial > How to convert uploaded files image files to jpg in PHP?

How to convert uploaded files image files to jpg in PHP?

WBOY
Release: 2016-10-18 08:56:03
Original
1559 people have browsed it

How to convert uploaded files image files to jpg in PHP?

Reply content:

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>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template