它不会传递变量吗?文件 php

发布于 2024-11-09 07:11:13 字数 1044 浏览 0 评论 0原文

我正在尝试使图像上传工作...

我有更多的表单元素,但我认为这

<form name="register" method="post" action="profiles.php" onSubmit="return validateForm()">

        <td class="col1">Profile Picture</td>
         <td class="col2">
            <input type="file" name="file" id="file">
        </td>

是唯一重要的部分,它传递到profiles.php。profiles.php

已传递表单的所有变量。 ...期待那个。 我收到错误“注意:未定义索引:文件”

这基本上是脚本中使用的所有文件......

    $target = "files/";

    echo $_FILES['file']['name'];
    //$image = basename($_FILES['file']['name']);
    //echo $image;
    $name = str_replace(' ', '_', $image);
    $target .= strtolower($name . uniqid());

    if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
    {

    //echo $firstName, $lastName, $UserName, $email, $DOB, $join, $gender, $likes; 
//just a test to see if they were working.


addEntry($firstName, $lastName, $UserName, $Password, $email, $DOB, $join, $gender, $likes, $description, $newlike, $target);
    }

I'm trying to make an image upload work...

I have a lot more elements of the form but I figure this the only important part

<form name="register" method="post" action="profiles.php" onSubmit="return validateForm()">

        <td class="col1">Profile Picture</td>
         <td class="col2">
            <input type="file" name="file" id="file">
        </td>

This is passed onto profiles.php

profiles.php has all the variables of the form passed through....expect for that one.
I get the error "Notice: Undefined index: file"

This is basically all file is used for in the script...

    $target = "files/";

    echo $_FILES['file']['name'];
    //$image = basename($_FILES['file']['name']);
    //echo $image;
    $name = str_replace(' ', '_', $image);
    $target .= strtolower($name . uniqid());

    if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
    {

    //echo $firstName, $lastName, $UserName, $email, $DOB, $join, $gender, $likes; 
//just a test to see if they were working.


addEntry($firstName, $lastName, $UserName, $Password, $email, $DOB, $join, $gender, $likes, $description, $newlike, $target);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梓梦 2024-11-16 07:11:13

尝试将 enctype="multipart/form-data" 添加到您的 html 表单标记中。 IE:

<form enctype="multipart/form-data">

Try adding enctype="multipart/form-data" to your html form tag. Ie:

<form enctype="multipart/form-data">
栖竹 2024-11-16 07:11:13

您的

中缺少 enctype="multipart/form-data"

You lack enctype="multipart/form-data" in your <form>.

偷得浮生 2024-11-16 07:11:13

您很可能没有在表单中定义文件上传元素“file”。

<input type="file" name="file" id="file" /> 

另请确保表单的 enctype"multipart/form-data"

<form action="upload.php" method="post" enctype="multipart/form-data">

Most likely you have not defined the file upload element 'file' in your form.

<input type="file" name="file" id="file" /> 

Also make sure your form's enctype is "multipart/form-data"

<form action="upload.php" method="post" enctype="multipart/form-data">
野却迷人 2024-11-16 07:11:13

兄弟 enctype="multipart/form-data"

Bro enctype="multipart/form-data"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文