简体   繁体   English

在Drupal上用PHP上传文件问题

[英]Uploading File Problem in PHP on Drupal

I don't know why but i had written clear cut code for uploading file in my page. 我不知道为什么,但是我写了清晰的代码在页面中上传文件。

i had written like this... on the client side. 我是这样写的...在客户端。

  <form id="recipeform" onsubmit="return checkAll()" action="submit.php" method="post" class="niceform" enctype="multipart/form-data">
 <input name="uploaded" type="file" />

And on submit.php... i am writting like this..... 在submit.php上...我这样写.....

$target = "newupload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else{
echo "Sorry, there was a problem uploading your file.";
}

simple code but then also i can't able to upload the file.. And i had made my webiste in Drupal. 简单的代码,但然后我也无法上传文件。.而且我在Drupal中建立了网站。

Thanks in advance. 提前致谢。 www.panchjanyacorp.com www.panchjanyacorp.com

Have you checked the PHP and/or server error logs? 您是否检查过PHP和/或服务器错误日志? Perhaps PHP's max upload size and/or an Apache-type LimitRequestBody is limiting upload file size and you're exceeding it. PHP的最大上传大小和/或Apache类型的LimitRequestBody可能限制了上传文件的大小,而您超出了它。

You should also check the $_FILES['uploaded']['error'] value, which will contain the error code for the upload operation. 您还应该检查$ _FILES ['uploaded'] ['error']值,该值将包含上载操作的错误代码。 Never assume that the upload succeeded... you should be doing at least the following: 永远不要假设上传成功...您应该至少执行以下操作:

if($_FILES['uploaded]['error'] === UPLOAD_ERR_OK) {
   ... handle upload here...
} else {
   ... handle error condition here ...
}

The full suite of error constants is defined here in the PHP docs. 完整的错误常量套件在PHP文档中定义

Oh, and be aware that your code is vulnerable to filename collisions. 哦,请注意您的代码容易受到文件名冲突的影响。 You will be overwriting existing files if one with the same basename is uploaded. 如果上载具有相同基本名称的文件,则将覆盖现有文件。 Perhaps this is what you intended, but just a friendly warning. 也许这就是您想要的,但只是一个友好的警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM