HTML代码上传图片 [英] HTML code to upload images

查看:902
本文介绍了HTML代码上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我提供一些链接(或源代码),供我研究如何将图像上载到网站(由社区),并让这些图像由社区在线查看。

b
$ b

我已经通过谷歌搜索,但没有运气。



谢谢。



编辑

对不起,我已经看到很多上传文件的例子。我希望(如果可能)能够上传图片,然后让他们安排在某种画廊中,以便社区可以看到/查看他们。



我如果可能的话,在WWW上提供一系列不同的技术。 复制下面的代码并将其保存为上传.php或anything.php(注意它应该保存为php扩展名,并且应该在apache服务器或任何支持php的服务器上运行)。

 <$ c如果(isset($ _ REQUEST ['submit']))
{
$ filename = $ _FILES [imgfile] [name]; $ c><?php
如果((($ _FILES [imgfile] [type] ==image / gif)||($ _FILES [imgfile] [type] ==image / jpeg )||($ _FILES [imgfile] [type] ==image / png)||($ _FILES [imgfile] [type] ==image / pjpeg))& &($ _FILES [imgfile] [size]< 200000))
{
if(file_exists($ _ FILES [imgfile] [name]))
{
echo文件名存在。;


{
move_uploaded_file($ _ FILES [imgfile] [tmp_name],uploads / $ filename);
echoUpload Successful。< a href ='uploads / $ filename'>点击此处< / a>查看上传的图片;
}
}
else
{
echoinvalid file。;
}
}
else
{
?>
< form method =postenctype =multipart / form-data>
档案名称:< input type =filename =imgfile>< br>
< input type =submitname =submitvalue =upload>
< / form>
<?php
}
?>

您应该在父目录中创建两个文件夹(uploads和tmp)该脚本执行)。



现在您的上传脚本已准备就绪。它只是一个上传脚本,您可以一次上传一张图片。

Can someone please provide me with some links (or source code) for me to research about how to upload images to a website (by the community) and for these images to be viewed online by the community.

I have searched via google, but have had no luck.

Thank you.

EDIT

Sorry, I have actually seen many examples to upload files. I am wanting (if possible) to be able to upload images, and then have them arranged in some kind of gallery so that the community can see/view them.

I am after a range of different technologies that are available on the WWW if possible.

解决方案

Copy the below codes and save it as upload.php or anything.php (note it should be saved as php extension and should be run on apache server or any server supporting php).

<?php
if(isset($_REQUEST['submit']))
{
  $filename=  $_FILES["imgfile"]["name"];
  if ((($_FILES["imgfile"]["type"] == "image/gif")|| ($_FILES["imgfile"]["type"] == "image/jpeg") || ($_FILES["imgfile"]["type"] == "image/png")  || ($_FILES["imgfile"]["type"] == "image/pjpeg")) && ($_FILES["imgfile"]["size"] < 200000))
  {
    if(file_exists($_FILES["imgfile"]["name"]))
    {
      echo "File name exists.";
    }
    else
    {
      move_uploaded_file($_FILES["imgfile"]["tmp_name"],"uploads/$filename");
      echo "Upload Successful . <a href='uploads/$filename'>Click here</a> to view the uploaded image";
    }
  }
  else
  {
    echo "invalid file.";
  }
}
else
{
?>
<form method="post" enctype="multipart/form-data">
File name:<input type="file" name="imgfile"><br>
<input type="submit" name="submit" value="upload">
</form>
<?php
}
?> 

And you should create two folders("uploads" and "tmp") in the parent directory (Where the script executes).

Now your upload script is ready. It's simply an upload script with which you can upload one image at a time.

这篇关于HTML代码上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆