【问题标题】:PHP - Change Content on Form Submit - UploadPHP - 更改表单提交的内容 - 上传
【发布时间】:2011-12-28 11:30:50
【问题描述】:

在成功上传时,我想用上传文件的缩略图替换用于上传文件的表单。这可能吗?

if uploaded = yes

show file

if uploaded = no

show form

基于 Codeigniter 和 Ion Auth

问候,

【问题讨论】:

  • 无法接受问题,因为从未找到解决方案 :(

标签: php mysql forms codeigniter authentication


【解决方案1】:
if (isset($_FILES['file']))

$image = $_FILES['file'];

echo '<img src="uploads/'.$file.'">';

else {

form here

}

然后您需要适当的代码将上传的文件从临时位置移动到该位置。

【讨论】:

  • $_FILES['file'] 文件名是什么?我的控制器里有什么?我的文件名采用 userid_filename.jpg 的形式
  • 是的,正确,因此“文件”将是您在表单中为控制器设置的任何内容,如您所说,然后您需要将文件移动到上传文件中并设置一个名称$文件。
【解决方案2】:

假设您有以下用于上传文件的输入框

<input name="logo" id="logo" class="input" type="file">

现在您可以通过以下方式访问它,

if($_FILES['logo']['name']!='')
{
         echo "file is uploaded do whatever you want with it";
}
else
{
           echo "error";
}

希望你明白

test.php

<?php
if(isset($_POST['submit']))
{
        if($_FILES['userfile']['name']!='')
        {
            echo "fine";
        }
        else
        {
            echo "not fine";
        }

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form method="POST"  enctype="multipart/form-data">
<input type="file" name="userfile" id="userfile" size="30" />
<input type="submit" value="submit" name="submit"/>
</form>

</body>
</html>

【讨论】:

  • 我在“logo”上有一个未定义的索引。
  • load->view('uploadform.tpl.php'); } ?>
  • 你用来上传文件的输入框的名称或id是什么? 'userfile' 是你输入框的名字和id吗?
  • 是的
  • 安全我更改了 ['name']!='userfile' 并显示了图像,尽管用户文件上仍未定义索引
【解决方案3】:

if(!$_POST['submit']) {

回声“”;

(你的表格放在这里)

<input type=\"submit\" name=\"submit\" value=\"upload\">

}否则 {

(如果他们按下提交,它会自动将他们带到此部分)
(在这里您将 INSERT 放入数据库脚本)

(这里也是你可以呼应图片的地方)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 2013-01-26
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    相关资源
    最近更新 更多