我之前看过"如何找到整个S3存储桶大小"的问题.这是一个不同的问题 - 所以如果它含糊不清,我会事先道歉.我会尽力解释我想要实现的目标.
我目前正在使用Amazon S3 PHP Class.
这就是我想要实现的目标:
我希望能够遍历我的MySQL数据库并在我的S3服务器上获取文件的特定文件名.(这可能基于用户).
在循环期间,查询Amazon S3存储桶(以某种方式)并获取MySQL循环中每个文件的文件大小.
添加所有文件大小,以获得一个大致的字节大小.
所以,基本上,假设我的用户在S3存储桶上有5个文件.我怎样才能查询S3存储桶,查看该用户的5个文件存储在存储桶中的数据量?
如果难以理解,我道歉.如果需要,我可以重新表达清楚.
任何朝着正确方向的推动都将非常感激.
我在弄清楚我做错了什么时遇到了一些困难.我的ActiveRecord查询正在返回nil,我认为这会导致NoMethodError被引发.
这就是我所拥有的:
@number_exclude_list = ["1234567890", "2223334545"]
@available_number = UserNumber.where.not(:user_num => @number_exclude_list)
Run Code Online (Sandbox Code Playgroud)
返回一组空行:
=> #<ActiveRecord::Relation []>
Run Code Online (Sandbox Code Playgroud)
那么,我有:
if (@available_number.empty?)
inform_user_empty
else
do_my_other_function
Run Code Online (Sandbox Code Playgroud)
但是,我得到:
`NoMethodError (undefined method 'inform_user_empty' for nil:NilClass)`
Run Code Online (Sandbox Code Playgroud)
我试过了:@available_number.blank?和`@available_number.nil?
我仍然得到相同的NoMethodError.我在这里做错了什么想法?
我有一个字符串:
$string = "R 124 This is my message";
Run Code Online (Sandbox Code Playgroud)
有时,字符串可能会发生变化,例如:
$string = "R 1345255 This is another message";
Run Code Online (Sandbox Code Playgroud)
使用PHP,删除前两个"单词"(例如,初始"R"然后是后续数字)的最佳方法是什么?
谢谢您的帮助!
我目前正在使用PHP/MySQL和jQuery timeago插件.基本上,我需要从数据库中提取时间戳并将其转换为ISO 8601格式.
像这样 2008-07-17T09:24:17Z
目前,我的时间戳以这种格式存在于数据库中:
0000-00-00 00:00:00
我已经尝试将timeago与我当前格式化的时间戳一起使用,但它不起作用.它总是说'不到一分钟前'.
但是,当我以ISO 8601格式对其进行硬编码时,它可以正常工作.因此,我需要一些帮助:
1)使用SELECT语句将我的时间戳转换为ISO 8601格式
2)或者,选择时间戳,然后使用PHP转换为ISO 8601.
非常感谢!!
我有三个与我合作的基本模型:
class User < ActiveRecord::Base
has_many :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :group
belongs_to :user
end
class Group < ActiveRecord::Base
has_many :assignments
end
Run Code Online (Sandbox Code Playgroud)
使用这个模式,我假设"Assignment"模型是连接表的一种,它保存用户属于哪些组的信息.所以,我想要做的是,使用User对象,找出它们属于哪些组.
在Rail控制台中,我正在执行以下操作:
me = User.find(1)
Run Code Online (Sandbox Code Playgroud)
它返回用户对象,应该如此.然后,我试图看看这个用户属于哪个"组",我认为它将通过"Assignment"模型.但是,我显然做错了什么:
me.groups
Run Code Online (Sandbox Code Playgroud)
哪个回报:
NoMethodError: undefined method `groups' for #<User:0x007fd5d6320c68>
Run Code Online (Sandbox Code Playgroud)
我怎样才能找出"我"对象属于哪个"群组"?
非常感谢!
我正在寻找最好的解决方案,我可以确保我正确地做到这一点:
我的网站上有一个日历,用户可以在其中使用日历iCal Feed并将其导入到他们偏好的外部日历中(Outlook,iCal,Google Calendar等).
为了阻止坏人抓取/搜索我的网站上的*.ics文件,我设置了Robots.txt来禁止存储订阅源的文件夹.
因此,基本上,iCal Feed可能如下所示:webcal://www.mysite.com/feeds/cal/a9d90309dafda390d09/feed.ics
据我所知,上面仍然是一个公共URL.但是,我有一个功能,用户可以根据需要更改其Feed的地址.
我的问题是:除Google日历外,所有外部日历都无法导入/订阅日历Feed.它会抛出消息:由于robots.txt限制,Google无法抓取该网址. 谷歌对此的回答.
因此,搜索后,我发现以下工作:
1)设置一个PHP文件(我正在使用),它本质上强制下载文件.它基本上看起来像这样:
<?php
$url = "/home/path/to/local/feed/".$_GET['url'];
$file = fopen ($url, "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
print $line;
}
fclose($file);
?>
Run Code Online (Sandbox Code Playgroud)
我尝试使用此脚本,它似乎与Google日历一起使用,没有任何问题.(虽然,我不确定它是否更新/刷新.我还在等着看它是否有效).
我的问题是:有没有更好的方法来解决这个问题?我想保留当前的Robots.txt以禁止抓取我的目录以获取*.ics文件并保持文件隐藏.
我在使用选项组的Rails中填充选择框时遇到一些困难grouped_options_for_select.
我目前有3个实例变量,我想将其添加到分组选择框的一个整个分组数组中.
例如,我有:
@fruits (which contains the object(s))
--- !ruby/object:Fruits
attributes:
id: 2
name: Banana
@veggies (which contains the object(s))
--- !ruby/object:Veggies
attributes:
id: 23
name: Celery
--- !ruby/object:Veggies
attributes:
id: 24
name: Carrots
@junk_food (which contains the object(s))
--- !ruby/object:Junk
attributes:
id: 11
name: Snickers
--- !ruby/object:Junk
attributes:
id: 12
name: Ice Cream
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何将这3个实例变量转换为分组选择,如:
<select>
<optgroup label="Fruits">
<option value="2">Banana</option>
</optgroup>
<optgroup label="Veggies">
<option value="23">Celery</option>
<option value="24">Carrots</option>
</optgroup>
<optgroup label="Junk">
<option value="11">Snickers</option>
<option value="12">Ice Cream</option>
</optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)
food_controller.erb …
我希望你能帮助我弄清楚为什么我会得到这个特殊的错误.
我有以下表格:
<%= form_for :response, :url => {:action => 'create'}, :remote => true do |f| %>
<%= f.hidden_field :template_id, :value => @template.id %>
<%= button_tag(type: 'submit', class: "btn btn-primary btn-lg pull-right next-slide") do %>
Next →
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
def create
@response = Response.new(response_params)
respond_to do |format|
if @result = @response.save
format.html
format.js
else
format.html { render :action => "new" }
format.js
end
end
end
Run Code Online (Sandbox Code Playgroud)
<% if @result %>
alert("Success!");
<% else %> …Run Code Online (Sandbox Code Playgroud) 我试图在一个页面上禁用Wordpress Yoast SEO,因为它与另一个插件冲突.
我尝试了这个StackOverflow问题,将此代码添加到functions.php:
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 ); // <-- check priority
}
}
Run Code Online (Sandbox Code Playgroud)
上面没有用,所以我然后跑过这个帖子,并尝试将其改为下面,这当然导致500错误.
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(5526)) {
global WPSEO_Frontend::get_instance()
remove_action( 'wp_head', array(WPSEO_Frontend::get_instance(), 'head'), 2 ); // <-- check priority
}
}
Run Code Online (Sandbox Code Playgroud)
关于如何在一个页面上禁用Yoast SEO的任何想法?我应该从functions.php或其他地方这样做吗?我想我很接近,但不是很接近.
我目前有以下查询:
SELECT group_concat(DISTINCT usrFirst, usrLast) as receiver_name //etc
Run Code Online (Sandbox Code Playgroud)
使用PHP时,它会输出我的名字列表,如下所示:
<?php
echo $row['receiver_name'];
//Outputs: JohnDoe,BillSmith,DaveJones
//Desired output: John Doe, Bill Smith, and Dave Jones
Run Code Online (Sandbox Code Playgroud)
我需要帮助搞清楚三件事:
如何在名字和姓氏之间加一个空格?
如何在每个逗号后插入一个空格?
如何在显示姓氏前添加"和"?