在哪里输入代码以将文件路径和当前会话ID插入数据库? [英] Where do I enter the code to insert file path and current session ID to the database?

查看:58
本文介绍了在哪里输入代码以将文件路径和当前会话ID插入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我试图简单地输入下面的图像路径,但我确定我没有在正确的位置插入声明。 PHP和MYSQL的新功能。



 <?  php   

session_start(); // 必须 start session first thing



// 此处 我们 < span class =code-summarycomment>运行 a login check

// 此处 我们 运行 a login check

$ toplinks = ;

if (isset($ _ SESSION ['id'])) {

// Put 已存储 session 变量 into local php variable

$ userid = $ _ SESSION [' id'];

$ username = $ _ SESSION [' username'];

$ toplinks =' < div id =Top_Links> ;< a href =logout.php>退出< / a>
< a href =member_account.php>我的帐户< / a>
< a href =member_profile.php?id ='
$ userid > ; '。 $ username。 '< / a > < span class =code-keyword>< / div > ';
}其他{
echo'请< a href = login.php > 登录< / a > 来访问您的帐户';
exit();
}
//将会话变量'id'放入本地变量
$ id = $ _SESSION ['id'];
//处理表单如果提交
if($ _FILES ['uploadedfile'] ['tmp_name']!=){
//对文件$运行错误处理b $ b //将最大文件大小限制设置为大约120kb
$ maxfilesize = 120000;
//检查文件大小,如果退出太大并告诉他们为什么
if($ _ FILES ['uploadedfile'] ['size']> $ maxfilesize){
echo< br / > < br / > 你的图片太大了。必须是100kb或更少,请< br / > < ; br / < span class =code-keyword>>
< a href = \ edit_pic.php \ > 点击此处< / a > 再试一次;
unlink($ _ FILES ['uploadedfile'] ['tmp_name']);
exit();
//检查文件扩展名是否为.jpg或.gif,如果没有退出并告诉他们为什么
}否则if(!preg_match(/ \。(gif | jpg)$ / i,$ _FILES ['uploadedfile'] ['name'])){
echo< br / > < br / > 您的图片不是.gif或.jpg,而且必须是这两种格式之一,请< br / >
< a href = \ edit_pic.php \ > 点击此处< / a > 再试一次;
unlink($ _ FILES ['uploadedfile'] ['tmp_name']);
exit();
//如果文件上没有错误处理它并上传到服务器
} else {
//重命名pic
$ newname =pic1.jpg;
//设置上传位置的direntory,使用成员ID命中他们的文件夹
//上传文件
if(move_uploaded_file($ _ FILES ['uploadedfile'] ['tmp_name '],memberFiles / $ id /\".$ newname)){
echo成功,图片已上传并将显示给访问者!< br / > < br / >
< a href = \ member_account.php \\ n > 点击此处< / a > 返回您的个人资料编辑区域;

$ file =memberFiles / $ id /\".$ newname;
$ sql =INSERT INTO file(path)VALUES('$ file');

if(!mysql_query($ sql))
{
die('Error:'。mysql_error());
}
echo< font size =' 5' > < < span class =code-leadattribute> font color = \ #0CF44A \ > SAVED TO DATABASE;


}否则{
echo上传文件时出错,请再试一次。如果连续失败,请通过电子邮件与我们联系。< br / > < br / >
< span class =code-keyword>< a href = \ member_account.php \ > 点击此处< / a > 返回您的个人资料编辑区;
exit();
}
} //在文件错误检查后关闭其他
} //关闭,如果发布表格
?>

解决方案

toplinks = ;

if (isset(


_SESSION ['id'])) {

// < span class =code-summarycomment> put 已存储 session 变量 into local php 变量
< span class =code-summarycomment>


userid =

I have tried to simply enter the image path below but I'm sure I don't have the insert statement in the right place. New to PHP and MYSQL.

<?php

session_start(); // Must start session first thing



// Here we run a login check

// Here we run a login check

$toplinks = "";

if (isset($_SESSION['id'])) {

    // Put stored session variables into local php variable

    $userid = $_SESSION['id'];

    $username = $_SESSION['username'];

    $toplinks = '<div id="Top_Links"><a  href="logout.php">Log Out </a>
             <a  href="member_account.php">My Account </a>
             <a  href="member_profile.php?id=' . $userid . '">' . $username . '</a> </div>';
} else {
   echo 'Please <a href="login.php">log in</a> to access your account';
  exit();
}
// Place Session variable 'id' into local variable
$id = $_SESSION['id'];
// Process the form if it is submitted
if ($_FILES['uploadedfile']['tmp_name'] != "") {
    // Run error handling on the file
    // Set Max file size limit to somewhere around 120kb
    $maxfilesize = 120000;
    // Check file size, if too large exit and tell them why
    if($_FILES['uploadedfile']['size'] > $maxfilesize ) {
        echo "<br /><br />Your image was too large. Must be 100kb or less, please<br /><br />
        <a href=\"edit_pic.php\">click here</a> to try again";
        unlink($_FILES['uploadedfile']['tmp_name']);
        exit();
    // Check file extension to see if it is .jpg or .gif, if not exit and tell them why
    } else if (!preg_match("/\.(gif|jpg)$/i", $_FILES['uploadedfile']['name'] ) ) {
        echo "<br /><br />Your image was not .gif or .jpg and it must be one of those two formats, please<br />
        <a href=\"edit_pic.php\">click here</a> to try again";
        unlink($_FILES['uploadedfile']['tmp_name']);
        exit();
        // If no errors on the file process it and upload to server
    } else {
        // Rename the pic
        $newname = "pic1.jpg";
        // Set the direntory for where to upload it, use the member id to hit their folder
        // Upload the file
        if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "memberFiles/$id/".$newname)) {
            echo "Success, the image has been uploaded and will display to visitors!<br /><br />
            <a href=\"member_account.php\">Click here</a> to return to your profile edit area";

        $file="memberFiles/$id/".$newname;
        $sql="INSERT INTO file (path) VALUES ('$file')";

        if (!mysql_query($sql))
        {
        die('Error: ' . mysql_error());
        }
        echo "<font size = '5'><font color=\"#0CF44A\">SAVED TO DATABASE";


        } else {
            echo "There was an error uploading the file, please try again. If it continually fails, contact us by email. <br /><br />
            <a href=\"member_account.php\">Click here</a> to return to your profile edit area";
            exit();
        }
    } // close else after file error checks
} // close if post the form
?>

解决方案

toplinks = ""; if (isset(


_SESSION['id'])) { // Put stored session variables into local php variable


userid =


这篇关于在哪里输入代码以将文件路径和当前会话ID插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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