我正在处理上传脚本.
如果用户上传文件并且它已经存在,我想警告用户(这完全是通过ajax)并给他们替换它的选项,或取消.
如果我可以将文件保留在tmp中并将回传到该文件的路径传递给ajax响应,我很好奇,而不是移动文件.
如果他们的用户说覆盖了旧文件,那么ajax请求会将路径传递给php继续处理该文件.
为此,我需要知道文件在php的tmp目录中停留多长时间
我总是听说在UNIX机器上找到临时文件夹的正确方法是查看TMP环境变量.在编写适用于Windows和Linux的代码时,我会检查TEMP和TMP.
今天,我发现我的Ubuntu安装根本就没有这个环境变量.
我知道你似乎总是可以依靠/ tmp来存放临时文件,但我知道TMP是用户可以告诉你将临时文件放在其他地方的方式.
那还是这样吗?
我们的Mysql查询使用临时表,在进程中创建临时文件.目前文件被写入/ tmp.mysql写入的临时文件夹的路径到底怎么改变?
我正在尝试使用php fopen函数将文件写入我的/ tmp目录(在apache服务器上),但它失败了:
<?php
$handle = fopen("/tmp/test.txt", "x");
if ($handle)
echo "Success!";
else
print_r(error_get_last());
Run Code Online (Sandbox Code Playgroud)
这将返回错误消息"无法打开流:没有此类文件或目录"./ tmp目录的权限设置为drwxrwxrwt,我可以看到Web用户正在向其写入其他文件.神奇的是,如果我将脚本指向具有权限777的另一个文件夹,它将返回成功.但我的open_basedir"没有价值".我有safe_mode = on和allow_url_fopen = off,但我认为不应该解释它吗?
这是关于apache 2.0的php 5.3.10.
为什么如果我NSTemporaryDirectory
用来保存我的图像,图像就会保存到
在/ var /文件夹/ OG/oGrLHcAUEQubd3CBTs-1zU +++ TI/-Tmp- /
而不是
/ Users/MyMac/Library/Application Support/iPhone Simulator/4.3.2/Applications/A685734E-36E9-45DD-BBE7-0A46F8F91DAF/tmp
这是我的代码:
-(NSString *)tempPath
{
return NSTemporaryDirectory();
}
-(void) saveMyFoto
{
NSString *urlNahledu = [NSString stringWithFormat:@"%@%@%@",@"http://www.czechmat.cz", urlFotky,@"_100x100.jpg"];
NSLog(@"%@", urlNahledu);
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlNahledu]]];
NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.8f)];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@ %@", paths, [self tempPath]);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"pkm.jpg"];
[data writeToFile:localFilePath atomically:YES];
}
Run Code Online (Sandbox Code Playgroud) 我发现了php
与/tmp
文件夹有关的奇怪行为.Php在使用时使用另一个文件夹/tmp
.PHP 5.6.7,nginx,php-fpm.
我以两种方式执行相同的脚本:通过浏览器和通过shell.但是当它通过浏览器启动时,文件不在真实/tmp
文件夹中:
<?php
$name = date("His");
echo "File /tmp/$name.txt\n";
shell_exec('echo "123" > /tmp/'.$name.'.txt');
var_dump(file_exists('/tmp/'.$name.'.txt'));
var_dump(shell_exec('cat /etc/*release | tail -n 1'));
Run Code Online (Sandbox Code Playgroud)
php -f script.php
File /tmp/185617.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
Run Code Online (Sandbox Code Playgroud)
文件在哪里?在/ tmp
$ find / -name 185617.txt
/tmp/185617.txt
Run Code Online (Sandbox Code Playgroud)
如果通过http://myserver.ru/script.php
我获取它
File /tmp/185212.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
Run Code Online (Sandbox Code Playgroud)
但文件在哪里?
$ find / -name 185212.txt
/tmp/systemd-private-nABCDE/tmp/185212.txt
Run Code Online (Sandbox Code Playgroud)
为什么php认为/tmp
应该在/tmp/systemd-private-nABCDE/tmp
?
在我的延迟作业中,我尝试创建一个文件到tmp文件夹
file_path = Rails.root.join('tmp', "#{file_name}." + file_extension);
exported_file = kit.to_pdf
# Save file to disk
File.open(file_path, 'wb') do |file|
file << exported_file
end
Run Code Online (Sandbox Code Playgroud)
它在本地运行良好但在Heroku上有延迟作业中的错误"没有这样的文件或目录 - /app/tmp/test.pdf"
那我怎么能解决这个问题呢.我不想在S3中存储文件.谢谢
我在Ubuntu 14.04上运行Rails 4.2.7.我编写了以下方法来帮助缓存一些数据(防止对我的PostGres 9.5数据库的命中)...
class Country < ActiveRecord::Base
has_many :states
def self.cached_find_by_iso(iso)
Rails.cache.fetch("#{iso}") do
find_by_iso(iso)
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,即使在运行rake tmp:cache:clear并重新启动我的服务器之后,我在尝试调用上面的时候遇到此错误...
Error during processing: Not a directory @ rb_file_s_rename - (/home/rails/myproject/tmp/cache/00020161104-1093-67j634, /home/rails/myproject/tmp/cache/001/000/)
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:528:in `rename'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1587:in `fu_each_src_dest0'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/fileutils.rb:517:in `mv'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/file/atomic.rb:36:in `atomic_write'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache/file_store.rb:83:in `write_entry'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache/strategy/local_cache.rb:115:in `write_entry'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:391:in `block in write'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:547:in `block in instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:547:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:389:in `write'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:588:in `save_block_result_to_cache'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache.rb:299:in `fetch'
/home/rails/myproject/app/models/country.rb:5:in `cached_find_by_iso'
/home/rails/myproject/app/services/all_events_guide_service.rb:84:in `block in process_page_data'
/usr/local/rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:187:in `block in …
Run Code Online (Sandbox Code Playgroud) 我正在使用Paperclip(2.3)处理在Ubuntu上运行的Rails 3.0.3应用程序上的图像上传.Paperclip正在处理上传广告,但是在应用程序的/ tmp文件夹中创建的RackMultipart*文件仍然存在 - 也就是说,它们只是累积而不是删除自己.我意识到我可以使用tmpreaper删除旧的tmpfiles,但我真的想找到一个更优雅(和可扩展)的解决方案.
我之前的问题是临时文件(即RackMultipart*文件)累积在Rails应用程序的根目录(而不是/ tmp)中.我通过在environment.rb文件中显式设置临时路径来解决这个问题,如下所示:
ENV['TMPDIR'] = Rails.root.join('tmp')
Run Code Online (Sandbox Code Playgroud)
是否需要设置另一个环境变量以确保正确处理临时文件 - 即在模型中保存后删除它们?我不确定这是Paperclip或我的Rails设置的问题.
我搜索过高低,但在这方面进展甚微.我会感激任何线索.
真诚的谢谢.
PS - 我正在使用S3进行存储.这似乎与问题无关 - 我在本地存储文件时遇到了同样的问题.
garbage-collection file-upload paperclip tmp ruby-on-rails-3