在php中上传文件的问题

在php中上传文件的问题

本文介绍了在php中上传文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用以下代码将文件上传并保存到php服务器中.但是文件没有上传..我的代码没有错误..请指导我哪里我错了???

Hi,

I am using following code to upload and save file to server in php. But file is not uploading.. there is no error in my code.. kindly guide me where i m wrong???

//file upload
<?php
//*******************************************
//           U P L O A D  F I L E
//*******************************************

$allowedExts ="ppt";

$extension = end(explode(".", $_FILES["file"]["name"]));

if (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"],
              "myphp/MyPP/" . $_FILES["file"]["name"]);
           echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
     }
    }
  }
else
  {
      echo "Invalid file";
  }

?>
.....


html代码


html code

<html>
<head>
</head>
<body>
<form  method="post" enctype="multipart/form-data">

Select Presentation  
<input type="hidden" name="upload" value="1" />
<input type ="file" id="file" />
<input type="submit" value="Upload" />


</form>
</body>
</html>



//*********************
//输出
//*********************
当我加载php页面时...显示以下消息...


(!)注意:未定义索引:第9行的C:\ wamp \ www \ fileUpload.php中的文件
调用堆栈
#时间记忆功能位置
1 0.0005 375624 {main}().. \ fileUpload.php:0


(!)警告:in_array()期望参数2为数组,第11行的C:\ wamp \ www \ fileUpload.php中给出的字符串
调用堆栈
#时间记忆功能位置
1 0.0005 375624 {main}().. \ fileUpload.php:0
2 0.0006 376008 in_array().. \ fileUpload.php:11
无效的文件

并且在上载事件上,此行为不会更改....



//*********************
// output
//*********************
when i load the php page... following messages are displayed...


( ! ) Notice: Undefined index: file in C:\wamp\www\fileUpload.php on line 9
Call Stack
#TimeMemoryFunctionLocation
10.0005375624{main}( )..\fileUpload.php: 0


( ! ) Warning: in_array() expects parameter 2 to be array, string given in C:\wamp\www\fileUpload.php on line 11
Call Stack
#TimeMemoryFunctionLocation
10.0005375624{main}( )..\fileUpload.php: 0
20.0006376008in_array ( )..\fileUpload.php:11
Invalid file

and on upload event this behavior does not change....

推荐答案




这篇关于在php中上传文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:47