【问题标题】:Upload script with output url insert into textbox to submit?上传带有输出 url 的脚本插入到文本框中提交?
【发布时间】:2014-07-18 16:52:41
【问题描述】:

对不起,我的英语不好。

我想要一个脚本,它有一个图像上传器,每次使用限制为 2mb 和一个文件,支持的扩展名:png、jpg、jpeg、gif。尺寸仅为 468*70。我需要在粘贴图片链接的文本框旁边有一个上传按钮,上传后,它将图片链接粘贴到该文本框。如果用户不想上传,他仍然可以粘贴链接并提交,我有我的提交按钮,你可以制作你的,我会重新编码。

图片例如:http://i.stack.imgur.com/rzcxv.png

if(empty($_POST) == false) {
$_POST['ip'] = htmlspecialchars($_POST['ip'], ENT_QUOTES);
$_POST['port'] = (int)$_POST['port'];
$banner   = htmlspecialchars($_POST['banner'], ENT_QUOTES);

if($banner !== ''){
    $imageProp = @getimagesize($banner);
    if($imageProp == false){
        $errors[] = "Banner link is not an image!";
    }
    if($imageProp[0] !== 468 || $imageProp[1] !== 60){
        $errors[] = "Banner is too large or too small, only 468 * 60 accepted. Your image has: " .$imageProp[0]." * ".$imageProp[1];
    }
}

<div class="form-group">
    <label>Banner (468 * 60) </label>
    <input class="form-control" type="text" name="banner" class="span4" /><br />
</div>

【问题讨论】:

  • getimagesize 需要通过支持的流式传输方法之一查看本地文件或远程文件。也许这个例子会有所帮助。 w3schools.com/php/php_file_upload.asp
  • 我有上传脚本,但我不知道如何将它链接到我的代码中名称为“banner”的文本输入。我希望它在上传完成后自动放置输出链接。我想要那个文本输入附近的按钮
  • 我的脚本只有一个文本输入框来放置链接。提交后,服务器将检查横幅的大小。但我想要一个上传按钮,浏览文件并将其上传到我的服务器,然后检查要求。如果通过,我服务器上的图像链接会自动放入该文本输入框

标签: php html css twitter-bootstrap


【解决方案1】:

有很多 PHP 教程可以帮助您处理文件上传的后端工作流程。您可能可以在前端处理文件类型验证和文件大小验证。

这里有一些用于表单前端演示的 Twitter Bootstrap。

<form class="form-inline" role="form" action="submit.php">
  <div class="form-group">
    <input type="file" id="img">
  </div>
  <div class="form-group">
    <input type="url" class="form-control" id="url" placeholder="Or enter a URL...">
  </div>
  <button type="submit" class="btn btn-default">Upload</button>
</form>

Learn more about Bootstrap's inline forms

用户提交表单后,您可以在模式中显示指向图像的链接。

Learn more about Bootstrap's modals

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 2021-11-15
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多