简体   繁体   English

html和php表单上传图片,然后经过处理后下载相同的图片

[英]html and php form to upload image, and then download the same image after processing

I asking for your help on how someone can upload a photo through a form, after posting, then the photo is modified in some way and immediately it downloads on the browser 我要求您提供帮助,以便他人在发布后如何通过表单上传照片,然后以某种方式修改照片并立即将其下载到浏览器中

-for now i know the parts about html form. -现在,我知道有关html表单的部分。 Is there a way that this can be done without saving file first in the server of course with PHP? 有没有一种方法可以不用先在PHP服务器中先保存文件就可以做到这一点?

Let me give my code here please help :( 让我在这里给我代码,请帮助:(

    // Loop $_FILES to execute all files
    foreach ($_FILES['photos']['name'] as $f => $name) {     
        if ($_FILES['photos']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['photos']['error'][$f] == 0) {             
            if ($_FILES['photos']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{
                // No error found! Move uploaded files 
                //if(move_uploaded_file($_FILES["photos"]["tmp_name"][$f], $path.$name))
                $count++; // Number of successfully uploaded file
                $img = $_FILES["photos"]["tmp_name"][$f];
                header('Content-Description: File Transfer');
                header('Content-Type: image/png');
                header('Content-Disposition: attachment; filename=Image.png');
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header('Pragma: public');
                $image = imagecreatefromjpeg($img);
                imagejpeg($image);
                imagedestroy($image);
                //echo $name;
                exit;
                //$zip->addFromString($_FILES["photos"]["name"][$f], $result['contents']);
            }
        }
    }
<?php

if(!$_FILES || is_uploaded_file($_FILES['html-input-name'])){
    //someone is trying to hack your upload
}else{
    $img = $_FILES['html-input-name'];
    header(...);//set a header


    ...// work your magic with the image

    echo $img;//finally echo the result
}

Take this example, and visit http://php.net/ and attempt to solve the problem, then come back when you get stuck. 以这个例子为例,并访问http://php.net/尝试解决问题,然后在遇到问题时返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM