php 入门型-文件上传代码

php 入门型-文件上传代码
<?php
 
 if(!empty($_FILES["uploadImage"])) {
    // get file name
  $filename = basename($_FILES['uploadImage']['name']);
  
  // get extension
    $ext = substr($filename, strrpos($filename, '.') + 1);
    
    // check for jpg only
    if ($ext == "jpg") {
        // generate unique file name
     $newName = 'images/'.time().'.'.$ext;
     
     // upload files
         if ((move_uploaded_file($_FILES['uploadImage']['tmp_name'], $newName))) {
   
          // get height and width for image uploaded
          list($width, $height) = getimagesize($newName);
          
          // return json data
             echo '{"image" : "'.$newName.'", "height" : "'.$height.'", "width" : "'.$width.'" }';
         }
         else {
             echo '{"error" : "An error occurred while moving the files"}';
         }
    }
    else {
       echo '{"error" : "Invalid image format"}';
    }
 }
?>

时间: 2024-07-31 18:04:37

php 入门型-文件上传代码的相关文章

PHP文件上传代码用法

  php文件上传代码编写过程 1. 先判断是否上传文件 2. 如果有再来判断上传中是否出错 3. 如果出错,则提示出错信息 4. 如查没出错,再判断文件类型 5. 如果类型符合条件,再判断指定目录中有没有存在该文件 6. 如果没有就把该文件移至指定目录 在php中上传文件必须知道的几个东西 $_FILES['myfile']['name'] 是指被上传文件的名称 $_FILES['myfile']['type'] 是指被上传文件的类型 $_FILES['myfile']['size'] 是指被

java 后台实现文件上传代码

问题描述 java 后台实现文件上传代码 java后台做一个文件上传,前端选择了照片点击上传到后台,后台需要保存到服务器上, 这个该怎么做,能不能贴一贴现成的代码?求解 解决方案 try { ??????????? FileItemFactory factory = new DiskFileItemFactory(); ??????????? ServletFileUpload upload = new ServletFileUpload(factory); ??????????? ??????

ajax+php 无刷新文件上传代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/1999/xhtml"> <head> <meta http-equiv="conte

ajax php多文件上传代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-

php简单实用文件上传代码(1/2)

<?php教程 if($_files['file']){  // ----------------------------------------------------------------------------------------------// // // 说明:文件上传   日期:2004-5-2 // // --------------------------------------------------------------------------------------

php 文件上传代码,限制jpg文件

php 文件上传代码,限制jpg文件 <?php     /* 图片上传类 www.lost63.com原创代码 仅限JPG格式图片 */     class uploadFile     {         var $inputName; //input名称         var $fileName; //文件命名         var $fileProperty; //文件属性         var $fileSize=2097152; //文件大小限制,2M         var

php最简单的文件上传代码

php最简单的文件上传代码 <?php    include("top.txt");    include("scripts.txt");    if(isset($_FILES['ufile']['name'])){        echo "Uploading: ".$_FILES['ufile']['name']."<br>";        $tmpName = $_FILES['ufile']['t

asp.net fileupload文件上传代码

asp教程.net fileupload文件上传代码 <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css教程" href="history/his

asp.net+jquery 文件上传代码(1/2)

asp教程.net+jquery 文件上传代码 <%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml