Php 我能';不要在线上传此代码中的任何文件,但它在本地工作
我有这个代码,它在本地主机上运行良好。但当我尝试在线打开它时,它不起作用。只是在图像中有一个错误。顺便说一下,我的连接文件是对的,我查对了。我对所有网站的文件夹拥有755权限Php 我能';不要在线上传此代码中的任何文件,但它在本地工作,php,mysql,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/
<!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>
";
}
}
?>
法提赫
tinyMCE.init({
//一般选择
模式:“文本区域”,
主题:“高级”,
插件:“自动链接、列表、分页符、样式、图层、表格、保存、advhr、advimage、advlink、情感、易趣、内嵌弹出窗口、插入日期时间、预览、媒体、搜索替换、打印、上下文菜单、粘贴、方向性、全屏、不可编辑、可视光标、不可中断、xhtmlxtras、模板、字数、advlist、自动保存”,
//主题选项
主题_高级_按钮1:“保存、新建文档、|、粗体、斜体、下划线、删除线、|、左对齐、居中对齐、右对齐、全对齐、样式选择、格式选择、字体选择、字体大小选择”,
主题高级按钮2:“剪切、复制、粘贴、粘贴文本、粘贴文字、搜索、替换、布利斯特、numlist、outdent、indent、blockquote、|、撤消、重做、链接、取消链接、锚定、图像、清理、帮助、代码、插入日期、插入时间、预览、前景色、后景色”,
主题|高级|按钮3:“表格控件,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,情感,易趣,媒体,advhr,|,打印,|,ltr,rtl,|,全屏”,
theme_advanced_按钮4:“插入层、向前移动、向后移动、绝对、|、styleprops、|、引用、缩写、首字母缩写、del、ins、attribs、|、visualchars、非中断、模板、分页符、restoredraft”,
主题\高级\工具栏\位置:“顶部”,
主题\高级\工具栏\对齐:“左”,
主题\高级\状态栏\位置:“底部”,
主题\u高级\u大小调整:正确,
//示例内容CSS(应该是您的网站CSS)
content\u css:“css/content.css”,
//链接/图像/媒体/模板对话框的下拉列表
template\u external\u list\u url:“lists/template\u list.js”,
外部链接列表url:“lists/link\u list.js”,
外部图片列表url:“lists/image\u list.js”,
媒体\u外部\u列表\u url:“lists/media\u list.js”,
//样式格式
样式和格式:[
{标题:“粗体文本”,内联:“b'},
{标题:'Red text',内联:'span',样式:{color:'#ff0000'}},
{title:'Red header',block:'h1',style:{color:'#ff0000'}},
{title:'example1',inline:'span',classes:'example1'},
{title:'example2',inline:'span',classes:'example2'},
{title:'表格样式'},
{title:'Table row 1',选择器:'tr',类:'tablerow 1'}
],
//替换模板插件的值
模板替换值:{
用户名:“某个用户”,
标记:“991234”
}
});
请选择一个文件:
标题:
作者:
日期:
正文:
参考您的代码:
if (!($uploadFile_type == "image/jpeg")) {
echo "Sorry, only GIF files are allowed.";
$uploadOk = 0;
}
能否检查$_FILES[“uploadFile”][“type”]是否实际返回“image/jpeg”?它给出了什么错误?echo“抱歉,只允许使用GIF文件。”;尝试使用GIF文件。如果它能工作,那么这就是web服务器上的php.ini文件或web服务器本身的配置问题,除了上传GIF文件之外,其他一切都会被禁止。如果它位于php.ini文件中,则可以通过添加要上载的其他类型文件的后缀来解决问题,但如果它位于服务器级别,则可能无法添加自己的后缀列表。(这个限制是一个安全措施。)我有同样的错误。我需要上传jpg文件。我不想要GIF,那么消息应该是“对不起,只允许JPG文件”实际上没有返回“image/jpeg”Ok,然后检查它返回的是什么类型。那是‘image/pjpeg’还是别的什么?如果是这样,请创建一个包含所有有效mime类型的数组,然后使用in_array函数检查上传文件的mime类型。请记住,不同的浏览器可以返回不同的mime类型,因此请在所有常见(流行)浏览器上测试您的代码。这也可能有用:
if (!($uploadFile_type == "image/jpeg")) {
echo "Sorry, only GIF files are allowed.";
$uploadOk = 0;
}