Php 尝试将图像上载到文件夹并在DB中保存其位置时出错

Php 尝试将图像上载到文件夹并在DB中保存其位置时出错,php,mysql,Php,Mysql,我不断地犯这个错误,我不知道为什么 上传表单 <?php require_once 'processor/dbconfig.php'; if(isset($_POST['submit'])) { if($_FILES['image']['name']) { $save_path="newimages"; // Folder where you wanna move the file. $myname = strtolower($_FILES['im

我不断地犯这个错误,我不知道为什么

上传表单

<?php
require_once 'processor/dbconfig.php';

if(isset($_POST['submit']))
{
    if($_FILES['image']['name'])
    {
      $save_path="newimages"; // Folder where you wanna move the file.
      $myname = strtolower($_FILES['image']['tmp_name']); //You are renaming the file here
      move_uploaded_file($_FILES['image']['tmp_name'], $save_path.$myname); // Move the uploaded file to the desired folder
    }

    $hl = $_POST['headline'];
    $fd = $_POST['feed'];
    $st = $_POST['story'];
    $tp = $_POST['type'];

    if($user->send($h1,$fd,$st,$tp,$save_path,$myname))
    {
        echo 'Success';
        $user->redirect("input.php");
    }
}
?>

<form enctype="multipart/form-data" method="post">
   <input type="text" name="headline">
   <input type="text" name="feed">
   <textarea cols="15" id="comment" name="story" placeholder="Message" rows="10"></textarea>
   <input type="text" name="type">
   <input type="file" name="image">
   <input type="submit" name="submit">
</form>
最后,这是我的错误

Warning: move_uploaded_file(newimages//var/tmp/phpyctf0k) [function.move-uploaded-file]: failed to open stream: No such file or directory in /nfs/c11/h05/mnt//domains/concept/html/input.php on line 12

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpyctf0K' to 'newimages//var/tmp/phpyctf0k' in /nfs/c11/h05/mnt//domains/concept/html/input.php on line 12
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

是的,我也创建了一个名为newimages的新文件夹。

所以你是说你在当前运行的php脚本
newimages
的同一相对目录中创建了一个文件夹,你想在其中上载此文件。只是要绝对清楚,这不是一条绝对的路径,这没关系

$save_path="newimages";
我认为它需要一个尾随斜杠,正如它出现在输出中一样,但不是出现在示例代码中

$save_path="newimages/";
在这一行中,您将临时文件的整个路径和文件名设置为绝对路径
/var/tmp/phpyctf0k

$myname = strtolower($_FILES['image']['tmp_name']); //You are renaming the file here
move_uploaded_file($_FILES['image']['tmp_name'], $save_path.$myname); // Move the uploaded file to the desired folder
因此,在这一行中,您将用temp文件的整个绝对路径
/var/tmp/phpyctf0k
追加本地相对路径
newimages
,因此现在这向PHP解释器表明您打算将文件移动到不存在的目录
newimages/var/tmp/phpyctf0k

$myname = strtolower($_FILES['image']['tmp_name']); //You are renaming the file here
move_uploaded_file($_FILES['image']['tmp_name'], $save_path.$myname); // Move the uploaded file to the desired folder
为了修复它,您可以使用类似

或者@Sean评论的
$\u文件['image']['name']

move_uploaded_file($_FILES['image']['tmp_name'], $save_path.strtolower($_FILES['image']['name'])); // Move the uploaded file to the desired folder

您的意思是,您已经在当前运行的php脚本的同一相对目录中创建了一个名为
newimages
的文件夹,您希望在其中上载此文件。只是要绝对清楚,这不是一条绝对的路径,这没关系

$save_path="newimages";
我认为它需要一个尾随斜杠,正如它出现在输出中一样,但不是出现在示例代码中

$save_path="newimages/";
在这一行中,您将临时文件的整个路径和文件名设置为绝对路径
/var/tmp/phpyctf0k

$myname = strtolower($_FILES['image']['tmp_name']); //You are renaming the file here
move_uploaded_file($_FILES['image']['tmp_name'], $save_path.$myname); // Move the uploaded file to the desired folder
因此,在这一行中,您将用temp文件的整个绝对路径
/var/tmp/phpyctf0k
追加本地相对路径
newimages
,因此现在这向PHP解释器表明您打算将文件移动到不存在的目录
newimages/var/tmp/phpyctf0k

$myname = strtolower($_FILES['image']['tmp_name']); //You are renaming the file here
move_uploaded_file($_FILES['image']['tmp_name'], $save_path.$myname); // Move the uploaded file to the desired folder
为了修复它,您可以使用类似

或者@Sean评论的
$\u文件['image']['name']

move_uploaded_file($_FILES['image']['tmp_name'], $save_path.strtolower($_FILES['image']['name'])); // Move the uploaded file to the desired folder

查看
$save\u path.$myname
=>
newimages//var/tmp/phpyctf0k
的结果。您需要更改
$myname=strtolower($\u FILES['image']['tmp\u name'])
$myname=strtolower($_文件['image']['name'])
当您想要
$\u文件['image']['name']
而不是
$\u文件['image']['tmp\u name']
问题时,2-在您的查询中,您有占位符
:foler
,但您绑定的是
:文件夹
可能重复查看
$save\u path.$myname
=>
新图像//var/tmp/phpyctf0k>。您需要更改
$myname=strtolower($\u FILES['image']['tmp\u name'])
$myname=strtolower($_文件['image']['name'])
当您想要
$\u文件['image']['name']
而不是
$\u文件['image']['tmp\u name']
问题时#2-在您的查询中,您有占位符
:foler
,但您正在绑定
:folder
在进行更改后,我收到此错误。。SQLSTATE[HY093]:无效参数编号:未定义参数那么您是否删除了
$save\u path
$myname
?好吧,奇怪的是尝试了肖恩所说的。。。。它仍然向我提供错误无效参数。。但它会将图像保存到文件夹中。。但它不会将任何内容保存到数据库中。@kevinm1990112qwq您的数据库查询
invaild参数
问题是因为您的查询中有
:foler
,但您绑定了
:folder
。基本打字error@Sean还有一个问题。。。当它在我的数据库中保存图像名称时,它将其保存为/var/tmp/phpdmnivo。。。但是在我的名为sp1.jpg的文件夹中,在做了更改之后,我收到了这个错误。。SQLSTATE[HY093]:无效参数编号:未定义参数那么您是否删除了
$save\u path
$myname
?好吧,奇怪的是尝试了肖恩所说的。。。。它仍然向我提供错误无效参数。。但它会将图像保存到文件夹中。。但它不会将任何内容保存到数据库中。@kevinm1990112qwq您的数据库查询
invaild参数
问题是因为您的查询中有
:foler
,但您绑定了
:folder
。基本打字error@Sean还有一个问题。。。当它在我的数据库中保存图像名称时,它将其保存为/var/tmp/phpdmnivo。。。但在我的文件夹中,它的名字是sp1.jpg