上传图片,然后在PHP中显示该图片 [英] upload an image and then display that image in PHP

查看:73
本文介绍了上传图片,然后在PHP中显示该图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于配置文件的网站,该配置文件将以HTML格式填写,而通过PHP的配置文件将由MYSQL存储.

我的问题是,会员将上传他们的个人资料照片.我要的是

1.将个人资料图片上传到服务器
2.将文件重命名为memberID
3.存储要由MySql存储的文件的链接(即upload \ memberid.jpg).

请帮助我解决问题.
我使用了以下代码

I am devolving a profile based website, where profiles will be filled up in HTML form and through PHP it will be store by MYSQL.

My problem is, the Member will upload their profile picture. What I want is to

1. upload the profile picture to the server
2. rename the file to memberID
3. Store the link of the file(i.e. upload\memberid.jpg) to be stored by MySql.

Please help me to solve the issue.
I used the following code

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> 


但想将文件重命名为memberid [some text field value].
我不希望错误消息文件已经存在.

请帮助我.


but want to rename the file to memberid[some text field value].
I don''t want the error message file already exist.

Please please help me.

推荐答案

allowedExts = array(" " gif" png");
allowedExts = array("jpg", "jpeg", "gif", "png");


扩展名 = end(explode(" .


_FILES [" file"] [ 名称"]))); 如果(((((
_FILES["file"]["name"])); if (((


这篇关于上传图片,然后在PHP中显示该图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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