- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个页面允许访客用户上传 xls 文件。如何确定该文件是否属于该用户所有?我将上传的文件重命名为 uniqid()
,并且在插入数据库时也存储了 uniqid()
,但问题是,uniqid()
> 来自数据库和 uniqid()
文件名不同。有人对这种情况有最好的方法吗?因为我不希望用户先登录才能上传文件。
这是我的 Controller :
function upload()
{
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
$file_ext = substr($filename, strripos($filename, '.')); // get file name
$filesize = $_FILES["file"]["size"];
$allowed_file_types = array('.doc','.docx','.xls','.xlsx');
if (in_array($file_ext,$allowed_file_types) && ($filesize < 200000))
{
// Rename file to uniqid()
$newfilename = uniqid($filename) . $file_ext;
if (file_exists("upload/" . $newfilename))
{
// file already exists error
echo "You have already uploaded this file.";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "kirim_undangan/" . $newfilename);
echo "File uploaded successfully.";
}
}
}
这是插入数据库时的代码:
function undangan()
{
$email = $this->input->post('email');
$from_nama = $this->input->post('from_nama');
$from_phone = $this->input->post('from_phone');
$data_user = array(
'email' => $email,
'name' => $from_nama,
'phone' => $from_phone,
'status'=> '0',
'unique_id'=> uniqid() //here is the uniqid that upload to database
);
$this->load->model('excel');
$this->excel->tambahuser($data_user); //sending data_user only
$data['msg'] = "Terima kasih ! Silahkan tunggu konfirmasi biaya melalui email !";
$this->load->library('email_ses');
$this->email_ses->send();
$data = json_encode(array("email" => $email, "from_nama" => $from_nama,"from_phone" => $from_phone ));
$this->load->view('kirimundangan.php',$data);
}
以及表单输入:
<div id="form_pesan">
<div action="<?php echo site_url('/kirim/upload'); ?>" class="dropzone" id="dropzone_form">
<div class="dz-message" data-dz-message><span><h4>Click or drop file here</h4></span></div>
</div>
<div class="row">
<div class="alert alert-danger" id="alert2" style="display: none;">Upload fail !
</div>
<div class="alert alert-info" id="alert_drpzone" style="display: none;">Success !
</div>
</div>
任何帮助将不胜感激..谢谢
最佳答案
由于您不希望用户登录,所以我能想到的唯一方法是使用COOKIE:http://php.net/manual/en/function.setcookie.php
// Rename file to uniqid()
$newfilename = uniqid($filename) . $file_ext;
if (file_exists("upload/" . $newfilename))
{
// file already exists error
echo "You have already uploaded this file.";
}
else
{
if(move_uploaded_file($_FILES["file"]["tmp_name"], "kirim_undangan/" . $newfilename)) {
// Set on upload success
setcookie("fileupload", $newfilename);
echo "File uploaded successfully.";
}
}
稍后检索:
$uploadImg = $_COOKIE["fileupload"];
但需要注意的是,用户可以关闭 Cookie,因此您需要提醒用户必须启用 Cookie。
关于php - 为上传的文件名和mysql数据库生成相同的uniqid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649245/
这两种生成顺序但有点独特的数字的方法之间的主要区别是什么?我想使用这样的数字作为 MySQL 数据库中的唯一用户 ID,以及作为密码的盐。 我的理解是,出于集群和索引的原因,这些 ID 应该是连续的(
我用这种方式在 PHP 中生成一个 5 个字母的 uniqid: $id = substr(uniqid(),0,5); 每次调用它时,我都会得到值 5004b。为什么会这样? 如果我删除 subst
我从 npm 安装了 uniqid,但是当我使用 uniqid() 时,它返回一个错误 TypeError: _uniqid.uniqid is not a function import { uni
今天我需要你的帮助。我实际上是在编写注册表单,对于每个新注册,我都会使用 uniqid() 函数生成一个 key 。 问题是当我尝试将生成的 key 插入数据库时出现此错误: Erreur: SQ
这个问题实际上并不是一个寻找解决方案的问题,它只是一个简单的好奇心问题。 PHP uniqid 函数有一个更熵标志,以使输出“更独特”。这让我想知道,当 more_entropy 为真时,这个函数产生
我正在使用其中一个来创建序列号。我想知道 md5(uniqid()) 或 md5(mktime()) 更好用吗? 哪一个的零钱较少而得到重复的 key ? 最佳答案 md5(uniqid("", tr
我正在学习如何使用唯一的 ID 重命名上传的图片(或文件),使其与其他上传的文件不同;将其保存到数据库中,以便可以将其作为用户图像调用并将其保存在图像文件夹中。 我的问题是,我已经弄清楚如何使用唯一的
我正在研究登录系统 http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqli
我正在尝试从手机上传图像并将其显示在图库页面上。我需要每个文件名都是唯一的,否则图像将覆盖自身。我有以下代码,其中 this topic 建议 $new_image_name但我似乎无法让它工作: i
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
我从不同的教程示例中整理了以下代码: fiddle :http://phpfiddle.org/main/code/27d-qfw 我想创建一个数字;当前时间,后跟一个 6 位随机数。 例如:201
我有一个有趣的例子,当本地托管在 XAMPP 上时,对 uniqid() 的多次重复调用不会生成唯一编号。唯一 ID 在任何地方重复 5-20 次,然后神秘地发生变化。 然而,有趣的是,该代码在我们的
如果我使用 PHP uniqid() 函数生成 ID,然后在 MySQL 中按字母顺序对 ID 进行排序,它们的顺序是否与创建时的顺序相同? 在我看来它们应该是这样的,因为 ID 只是递增的十六进制字
全部, 我想在注册过程中生成服务器端用户ID。这个 id 应该是连续的以允许聚集索引。显然,它还需要是独一无二的。 为此,我可以在多大程度上使用 uniqid("")?我不是在构建谷歌,我假设 2 个
我有以下内容,但收到错误消息,指出键应该是唯一的,并且它指的是跨度。 uniqid ... const displayResults = (list: any) => { const
函数 uniqid() 可能包含哪些可能的字符?据我了解,这只是字母数字字符,但需要您确认。那么,是这样吗? 附言在文档中 http://php.net/manual/en/function.uniq
我希望修改下面的代码以接受随机生成的唯一 ID 以使用 php uniqid 函数替换名称。我尝试了几种方法但没有成功。 move_uploaded_file($_FILES["file"]["tm
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: PHP short hash like URL-shortening websites 我需要一个函数,我可
这个函数在 javascript 中的等价物是什么: http://php.net/manual/en/function.uniqid.php 基本上我需要生成一个随机 ID,如下所示:a4245f5
尝试在 C# 中复制一些 PHP 代码。 PHP 代码使用 uniqid 函数,并将 more entropy 参数设置为 true。知道如何在 C# 中最好地复制它吗? http://us2.php
我是一名优秀的程序员,十分优秀!