我需要合并两个代码,我有一个单独的文件用于页面创建和上传 [英] i need to merge two codes i have a separate file for page creation and uploading

查看:86
本文介绍了我需要合并两个代码,我有一个单独的文件用于页面创建和上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php新手为我的项目开发cms而且我无法在数据库中插入图像或文件而且我的字段是id,information_id,menu,position,visible,img_des,image,content我只是添加一个图像到现在这个问题是我不知道在哪里放置代码以及如何改变

这里我的页面创建:

合并代码



 if(isset($ _ POST [submit])&& $ _FILES ['  userfile'] ['  size'] > 0)
{ / * 因此,如果设置了,我们将运行验证,* /
$ errors = array();

// 表格验证
$ required_fields = array(' menu'' position'' visible'' img_des'' content');
$ errors = array_merge($ errors,check_required_fields($ required_fields,$ _POST));

$ fields_with_lengths = array(' 菜单' => 30);
$ errors = array_merge($ errors,check_max_field_lengths($ fields_with_lengths,$ _POST));

// 在放入数据库之前清理数据

$ information_id = mysql_prep($ _ GET [' 信息]);
$ menu = trim(mysql_prep($ _ POST [' 菜单'])); // 剪切菜单的空白

$ position = mysql_prep($ _ POST [' position']);
$ visible = mysql_prep($ _ POST [' 可见的]);
$ img_des = mysql_prep($ _ POST [' img_des' ]);
$ content = mysql_prep($ _ POST [' 含量]);


if(空($ errors)){
$ query = INSERT INTO页面(
菜单,位置,可见,img_des,图片,内容,information_id
)价值(
' {$ menu}',{$ position},{$ visible},'{$ img_des}','{$ image}','{$ content}',{$ information_id}
;





上传代码:



 <?php  
require_once ' 包括/ session.php文件';
require_once ' includes / connect.php';
require_once ' includes / functions.php';
if(isset($ _ POST [' upload'])&& $ _FILES [' userfile'] [' < span class =code-string> size'
]> 0)
{
$ fileName = $ _FILES [< span class =code-string>' userfile'] [' 名称];
$ tmpName = $ _FILES [' userfile '] [' tmp_name'];
$ fileSize = $ _FILES [' userfile '] [' size'];
$ fileType = $ _FILES [' userfile '] [' type'];

$ fp = fopen($ tmpName,' R');
$ content = fread($ fp,filesize($ tmpName));
$ content = addslashes($ content);
fclose($ fp);

if(!get_magic_quotes_gpc())
{
$ fileName = addslashes($ fileName);
}


$ query = < span class =code-string> INSERT INTO upload(名称,大小,类型,内容)

VALUES('$ fileName','$ fileSize','$ fileType','$ content' );

mysql_query($ query) die(' 错误,查询失败');


echo < br>文件$ fileName已上传< br>;
}
?>

解决方案

_POST [submit])&&


_FILES [' userfile'] [' size']> 0)
{ / * 因此如果设置了,我们将运行验证,* /


errors = array();

// 表格验证

i am new to php an developing cms for my project and am not able to insert a image or file in a database and my fields are id, information_id, menu, position, visible, img_des, image, content i just add a image to this now the problem is i dont know where to put the code and how to make alter
here my page creation :
MERGE THE CODE

if(isset($_POST[submit])&& $_FILES['userfile']['size'] > 0)
{                  /*    So if it is set we�ll run for validation, */
$errors = array();

// Form Validation
$required_fields = array('menu', 'position', 'visible', 'img_des', 'content');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));

$fields_with_lengths = array('menu' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

// clean up data before putting in the database

 $information_id = mysql_prep($_GET['info']);
 $menu = trim(mysql_prep($_POST['menu']));  // cut out whitespace for menu

 $position = mysql_prep($_POST['position']);
 $visible = mysql_prep($_POST['visible']);
 $img_des = mysql_prep($_POST['img_des']);
 $content = mysql_prep($_POST['content']);


 if(empty($errors)){
 $query = "INSERT INTO pages (
 menu, position, visible, img_des, image, content, information_id
 ) VALUES (
 '{$menu}', {$position}, {$visible}, '{$img_des}', '{$image}', '{$content}',                                             {$information_id}
    )";



uploading code:

<?php
require_once 'includes/session.php';
require_once 'includes/connect.php';
require_once 'includes/functions.php';
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed'); 


echo "<br>File $fileName uploaded<br>";
} 
?>

解决方案

_POST[submit])&&


_FILES['userfile']['size'] > 0) { /* So if it is set we�ll run for validation, */


errors = array(); // Form Validation


这篇关于我需要合并两个代码,我有一个单独的文件用于页面创建和上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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