我要求您提供有关如何通过表单上传照片的帮助,发布后,然后以某种方式修改照片并立即在浏览器上下载
- 现在我知道关于html表单的部分。 有没有办法可以在没有首先在服务器中保存文件的情况下使用PHP来完成?
让我在这里给我的代码请帮助:(
// 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']);
}
}
}
答案 0 :(得分:0)
<?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
}
以此为例,访问http://php.net/并尝试解决问题,然后在遇到问题时再回来。