gpt4 book ai didi

php - 为什么这个 php 不起作用,我得到 undefined index ...?

转载 作者:行者123 更新时间:2023-11-30 23:50:16 25 4
gpt4 key购买 nike

我正在尝试将图像上传到服务器。

我有一个包含几个输入的表单...在此表单内,我有一个 Iframe,其中包含另一个用于上传的表单,这是因为我不希望原始表单提交()。

原始形式基本上是:

      <form> ...... bla bla bla alot of inputs....<iframe src="pic_upload.html"></iframe></form>

这是 pic_upload.html:

      </head>
<body><form name="pic_form" id="pic_form" action="bincgi/imageUpload.php" method="post" target="pic_target"><input name="pic_file" type="file" id="pic_file" size="35" onchange="this.form.submit();"></form><div id="pic_target" name="pic_target" style="width:80px; height:80px;"></div></body>
</html>

这是 imageUpload.php:

      <?php
$destination_path = getcwd().DIRECTORY_SEPARATOR;
//echo $destination_path;
$result = 0;
$target_path = $destination_path . basename($_FILES['pic_file']['name']);
if(@move_uploaded_file($_FILES['pic_file']['tmp_name'], $target_path)) {
$result = 1;
}
?>

我收到此错误:未定义索引:imageUpload.php 中第 5 行的 pic_file

另外,如果我让它工作,有没有一种好的方法可以在表单的目标中显示上传的图像?

非常感谢!PS:我会将 javascript 添加到标签中,因为也许这就是我需要的!

最佳答案

不要忘记表单属性

enctype="multipart/form-data"

关于php - 为什么这个 php 不起作用,我得到 undefined index ...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1692934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com