Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP文件上传程序不工作_Php - Fatal编程技术网

PHP文件上传程序不工作

PHP文件上传程序不工作,php,Php,我什么都试过了。当我想在我的服务器上上传foto时,名称是write to db,但并没有上传到服务器上 HTML <form role="form" action="db_work.php?index=list_slider&action=new" method="post" ENCTYPE="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="512000"/> 此脚本

我什么都试过了。当我想在我的服务器上上传foto时,名称是write to db,但并没有上传到服务器上

HTML

<form role="form" action="db_work.php?index=list_slider&action=new" method="post" ENCTYPE="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="512000"/>
此脚本位于文件夹admin中。根目录中是文件夹上载。


<!doctype html>
<html lan="en">
<head>
<title>Upload Script</title>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<table align="center" width="60%">
<tr>
<td colspan="3" align="center">
<h2>Upload Image</h2>
</td>
</tr>
<input type="hidden" name="insert" value="updetails" />
<tr>
<td><label for="photo">Upload Image</label></td>
<td width="5%">:</td>
<td><input name="uploadimage" type="file" id="photo" /></td>
</tr>
<tr height="20"> </tr>
<tr>
<td colspan="3" align="center">
<input type="reset" value="Reset" />
<input type="submit" value="Upload" name="submit"/>
</td>
</tr>
</table>
</form>
</body>
</html>
上传脚本 上传图像 上传图像 :
uploader.php

if($_POST['submit']=='Upload')
{
    $allowedExts = array("gif", "jpeg", "jpg", "png");

    $info = pathinfo($_FILES['uploadimage']['name']);
    $ext = $info['extension']; // get the extension of the file

    $target_path = "uploads/";
    $target_path = $target_path.str_replace(' ', '_', $_FILES["uploadimage"]["name"]);

    if ((($_FILES["uploadimage"]["type"] == "image/gif") || ($_FILES["uploadimage"]["type"] == "image/jpeg")
        || ($_FILES["uploadimage"]["type"] == "image/jpg") || ($_FILES["uploadimage"]["type"] == "image/pjpeg")
        || ($_FILES["uploadimage"]["type"] == "image/x-png")|| ($_FILES["uploadimage"]["type"] == "image/png"))
        && ($_FILES["uploadimage"]["size"] < 5242880) && in_array($ext, $allowedExts))  //5242880 Maximum File size in bytes (5mb)
    {
        if ($_FILES["uploadimage"]["error"] > 0) {
            echo "Return Code: " . $_FILES["uploadimage"]["error"] . "<br>";
        }
        else {
            move_uploaded_file($_FILES['uploadimage']['tmp_name'], $target_path);

            echo "<br />The image ".  basename( $_FILES['uploadimage']['name'])." has been uploaded";

        }
    }
    else
    {
        echo "Invalid file";
    }
}
else
{
    echo"<br /><b>You Dont have permission to open this Page</b>";
}
if($\u POST['submit']=='Upload')
{
$allowedExts=数组(“gif”、“jpeg”、“jpg”、“png”);
$info=pathinfo($_文件['uploadimage']['name']);
$ext=$info['extension'];//获取文件的扩展名
$target_path=“uploads/”;
$target_path=$target_path.str_replace(“,”,$文件[“uploadimage”][“name”]);
如果(($_文件[“uploadimage”][“type”]=“image/gif”);|($_文件[“uploadimage”][“type”]=“image/jpeg”)
||($_文件[“uploadimage”][“type”]=“image/jpg”)| |($_文件[“uploadimage”][“type”]=“image/pjpeg”)
||($_文件[“uploadimage”][“type”]=“image/x-png”)| |($_文件[“uploadimage”][“type”]=“image/png”))
&&($_FILES[“uploadimage”][“size”]<5242880)和&in_数组($ext,$allowedExts))//5242880以字节为单位的最大文件大小(5mb)
{
如果($_文件[“uploadimage”][“error”]>0){
echo“返回代码:”.$\u文件[“uploadimage”][“错误”]。
; } 否则{ 移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\; echo“
图像”.basename($_文件['uploadimage']['name'])”已上载; } } 其他的 { 回显“无效文件”; } } 其他的 { echo“
您没有打开此页面的权限”; }
if(在_数组($fileParts['extension',$fileTypes])中)的结果是什么?p.s.处理上载的方式非常不安全。请确保已打开错误显示和报告。例如,
ini\u集('display\u errors',1);ini_集(“日志错误”,1);ini_集('error_log',dirname(_文件).'/error_log.txt');错误报告(E_全部)我有它$targetFolder='uploads/foto/slider';有错误。”/uploads/foto/slider'正确您可以在成功上载到服务器时写入db,方法是在以下位置添加db insert(移动\u上传的\u文件($\u文件['uploadimage']['tmp\u名称'],$target\u路径)){db insert语句…}您使用的是$\u服务器['DOCUMENT\u ROOT']。可能存在某些服务器的根目录权限问题。。所以最好使用相对路径上传文件。
if($_POST['submit']=='Upload')
{
    $allowedExts = array("gif", "jpeg", "jpg", "png");

    $info = pathinfo($_FILES['uploadimage']['name']);
    $ext = $info['extension']; // get the extension of the file

    $target_path = "uploads/";
    $target_path = $target_path.str_replace(' ', '_', $_FILES["uploadimage"]["name"]);

    if ((($_FILES["uploadimage"]["type"] == "image/gif") || ($_FILES["uploadimage"]["type"] == "image/jpeg")
        || ($_FILES["uploadimage"]["type"] == "image/jpg") || ($_FILES["uploadimage"]["type"] == "image/pjpeg")
        || ($_FILES["uploadimage"]["type"] == "image/x-png")|| ($_FILES["uploadimage"]["type"] == "image/png"))
        && ($_FILES["uploadimage"]["size"] < 5242880) && in_array($ext, $allowedExts))  //5242880 Maximum File size in bytes (5mb)
    {
        if ($_FILES["uploadimage"]["error"] > 0) {
            echo "Return Code: " . $_FILES["uploadimage"]["error"] . "<br>";
        }
        else {
            move_uploaded_file($_FILES['uploadimage']['tmp_name'], $target_path);

            echo "<br />The image ".  basename( $_FILES['uploadimage']['name'])." has been uploaded";

        }
    }
    else
    {
        echo "Invalid file";
    }
}
else
{
    echo"<br /><b>You Dont have permission to open this Page</b>";
}