PHP文件上传失败 [英] PHP File Upload Failing

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

问题描述


$ b

 <?php $ b $由于某种原因,我的PDF上传表单失败了,我有这样的代码:

b if($ _ POST [submit] ==将PDF添加到Comm和特殊项目)
{
$ addsubp = $ _POST [addsubp];
$ addsubp_name = $ _POST [addsubp_name];
$ commuploadedfile = $ _FILES ['uploadedfile'] ['name'];
$ sqldoc =INSERT INTO projects_links(pid,display_name,link)VALUES('。$ addsubp。','。。$ addsubp_name。','。。$ commuploadedfile。');
mysql_query($ sqldoc)或die(mysql_error());
回显< BR>;
$ target_path =D:\\Hosting\\\\\\\\\\\\\\\\\\\\\\\\\\'
$ target_path = $ target_path。 basename($ _FILES ['uploadedfile'] ['name']);

if(move_uploaded_file($ _ FILES ['uploadedfile'] ['tmp_name'],$ target_path)){
echo< br>文件。 basename($ _FILES ['uploadedfile'] ['name'])。
已上载< br>;
} else {
echo< br>上传文件时出现错误,请重试。< br>;
}
}
?>
< form method =post>
将PDF添加到针对委员会和特殊项目的项目中< br>选择项目< select name =addsubp><?php

$ query =SELECT
projects 。*
FROM
个项目;
$ showresult = mysql_query($ query);
$ csp_c = 1; ($ buyarray = mysql_fetch_assoc($ showresult))
{
echo< option value =。$ buyarray ['id']。>。$ buyarray [ PNAME ]。 < /选项>中;
}

?>< / select>< br>
选择PDF的显示名称< input type =textname =addsubp_name/> <溴>
选择PDF:< input name =uploadedfiletype =file/> <峰; br>
< input type =submitvalue =将PDF添加到Comm和特殊项目name =submit/>
< / form>

我确定应用程序对comm目录具有写权限。我有godaddy,并使用文件管理器来确保。之前我在这个项目中遇到过权限问题,所以我知道这不是事实。它保持打印



上传文件时出现错误,请重试。



不会尝试上传任何PDF,我做错了什么?
thanks!

解决方案

您可能有权限问题,但对于文件上传,您的表单标记应包含适当的enctype属性。
$ b

< form enctype =multipart / form-datamethod =POST>



并定义文件大小限制也是一个好主意:

<输入类型=hiddenname =MAX_FILE_SIZEvalue =1000000/>


For some reason my PDF upload form is failing consistently, I have this code:

<?php
if($_POST["submit"] == "Add PDF to Comm and Special Projects")
{
    $addsubp = $_POST["addsubp"];
    $addsubp_name = $_POST["addsubp_name"];
    $commuploadedfile = $_FILES['uploadedfile']['name'];
    $sqldoc = "INSERT INTO projects_links (pid, display_name, link) VALUES ('".$addsubp."','".$addsubp_name."','".$commuploadedfile."')";
    mysql_query($sqldoc) or die(mysql_error()); 
    echo "<BR>";
    $target_path = "D:\\Hosting\\69903\\html\\pdfs\\comm\\";    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "<br>The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded<br>";
    } else{
        echo "<br>There was an error uploading the file, please try again.<br>";
    }
}
?>
<form method="post">
Add PDF to Project for Committees and Special Projects <br>Choose Project<select name="addsubp"><?php

$query = "SELECT
projects.*
FROM
projects";
$showresult = mysql_query($query);
$csp_c = 1;
while($buyarray = mysql_fetch_assoc($showresult))
{
    echo "<option value=".$buyarray['id'].">".$buyarray["pname"]."</option>";
}

?></select><br>
Choose Display Name for PDF <input type="text" name="addsubp_name" /> <Br>
Choose PDF: <input name="uploadedfile" type="file" /> <Br>
<input type="submit" value="Add PDF to Comm and Special Projects" name="submit" />
</form>

I have made sure that the application has write privileges to the "comm" directory. I have godaddy and used the file manager to make sure of that. I have had problems with permissions in this project before, so I know this isn't case. It keeps printing

There was an error uploading the file, please try again.

It doesn't attempt to upload any PDF at all, what am I doing wrong? thanks!

解决方案

You may have permissions issues, but for file uploads your form tag should contain the proper enctype attribute.

<form enctype="multipart/form-data" method="POST">

and defining a file size limit is also a good idea:

<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />

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

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