我无法在线上传此代码中的任何文件,但在本地工作

时间:2014-11-28 06:45:17

标签: php mysql

我有这个代码,它在我的本地主机本地运行良好。但是当我尝试在线打开它时它不起作用。只是在图像中有错误。顺便说一句,我的连接文件是正确的,我颊了。我对所有网站的文件夹拥有755的权限。

<!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-Type"
    content="text/html; charset=utf-8" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<title>Fatih</title>
<script type="text/javascript" src="../tiny/tiny_mce.js"></script>

<script type="text/javascript">
    tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        content_css : "css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Style formats
        style_formats : [
            {title : 'Bold text', inline : 'b'},
            {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
            {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
            {title : 'Example 1', inline : 'span', classes : 'example1'},
            {title : 'Example 2', inline : 'span', classes : 'example2'},
            {title : 'Table styles'},
            {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
        ],

        // Replace values for the template plugin
        template_replace_values : {
            username : "Some User",
            staffid : "991234"
        }
    });
</script>
<link href="css.css" rel="stylesheet" type="text/css" />

</head>

<body>

<form action="addarticle.php" method="post" enctype="multipart/form-data">
  Please choose a file: <input type="file" name="uploadFile"><br>

  title : <input type="text" class="name" name="name" value=""></br>
  auther : <input type="text" class="name" name="auther" value=""></br>
  date : <input type="text" class="name" name="date" value=""></br>
      text :          <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
                    </textarea>
  <input type="submit" class="botton" value="insert" name="go"><br>

</form> 


<?
    include '../include/config.php';
?>





<?php
    if ($_POST['go']){
    $id = $_POST['id'];
    $name = $_POST['name'];
    $auther = $_POST['auther'];
    $text = $_POST['elm1'];
    $date = $_POST['date'];
    $namei = $_POST['namei'];

$target_dir = "../images/article/";
$target_dir = $target_dir . basename( $_FILES["uploadFile"]["name"]);
$uploadOk=1;

// Check if file already exists
if (file_exists($target_dir . $_FILES["uploadFile"]["name"])) {


    echo "Sorry, file already exists.";
    $uploadOk = 0;
}

// Check file size
if ($uploadFile_size > 5000000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}

// Only GIF files allowed
if (!($uploadFile_type == "image/jpeg")) {
    echo "Sorry, only GIF files are allowed.";
    $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
        echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";
        $namei = basename( $_FILES["uploadFile"]["name"]);

          $add = mysql_query("insert into article values ('','$name','$auther','$text','$date','$namei')");






    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}




echo " 
    <div class='imagest'>
    this is mine 
    <img class='imagest'src='../images/article/$namei'> 
    </div>
    ";

    }




    }


?>

2 个答案:

答案 0 :(得分:1)

if (!($uploadFile_type == "image/gif")) {
    echo "Sorry, only GIF files are allowed.";
    $uploadOk = 0;
}

答案 1 :(得分:1)

参考您的代码:

if (!($uploadFile_type == "image/jpeg")) {
    echo "Sorry, only GIF files are allowed.";
    $uploadOk = 0;
}

你能检查$ _FILES [“uploadFile”] [“type”]是否实际上正在返回'image / jpeg'吗?