首页 \ 问答 \ 通过终端将PHP生成的CSV文件上传到SFTP服务器(Uploading a PHP generated CSV file to SFTP server via terminal)

通过终端将PHP生成的CSV文件上传到SFTP服务器(Uploading a PHP generated CSV file to SFTP server via terminal)

我有一个PHP文件,使用以下代码生成CSV文件:

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;

我没有包含创建内容的代码,因为它的工作正常。 我需要做的是使用终端运行此文件并将结果上传到sftp服务器。 我可以在终端连接到服务器。

我一直在终端中使用php命令生成生成的CSV。 但是,这不会像在浏览器中运行时那样生成CSV。 它做的是将CSV作为字符串生成。

有没有办法将CSV生成为像浏览器这样的文件,以便我可以在终端中获取它并将其上传到SFTP服务器? 或者可以回显出PHP文件生成的字符串,并使用这种命令自己创建CSV:

echo "boo,to,you">file.csv

I have a PHP file which generates a CSV file using the code below:

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;

I've not included the code which creates the content as it does it's job fine. What I need to do is use terminal to run this file and upload the results to an sftp server. I can connect to the server fine in terminal.

I have been using the php command in terminal to produce the resulting CSV. This however doesn't produce the CSV like it does when run in the browser. What it does do is produce the CSV as a string.

Is there a way to either produce the CSV as a file like the browser so I can grab it in terminal and upload it to the SFTP server? Alternatively is it possible to echo out the string produced from the PHP file and create the CSV myself using this kind of command:

echo "boo,to,you">file.csv

原文:https://stackoverflow.com/questions/27508296
更新时间:2023-05-11 06:05

最满意答案

首先, 关闭 animation库并使用ObjectAnimator库。 它更新,更有用100倍。

然后,使用AnimatorSet播放动画。 AnimatorSets可以按顺序播放动画或按顺序播放动画。 您可以创建动画,并使用AnimatorSet#BuilterAnimatorSet#playSequentially将其全部按顺序播放。

然后,不要担心垃圾收集和清理。 只要将它们从View中删除,垃圾收集器就会在它准备好时清除它们。 但是,您可以通过每次回收和重新使用ImageView来考虑更高效的策略。 这样你不会不断重建它们。 此外,它可以防止大量沉重,不必要的垃圾收集。 如果动画频繁发生,这只需要考虑。


First, ditch the animation library and use the ObjectAnimator library. It's newer and 100x more useful.

Then, use an AnimatorSet to play the animations. AnimatorSets can play animations either sequentially or in order. You can just create your animations and either use the AnimatorSet#Builter or the AnimatorSet#playSequentially to play them all in order.

Then, don't worry about the garbage collection and cleanup. Just remove them from View and the garbage collector will clean them up when it's ready. However, you may consider a more efficient strategy by recycling and re-using the ImageViews each time. That way you're not re-building them constantly. Also, it prevents a lot of heavy, unnecessary garbage collecting. This would only need to be considered if the animations happen frequently.

相关问答

更多
  • 如果要为布局内的视图设置动画,则使用布局动画会更容易。 基本上,您需要加载动画,创建LayoutAnimationController ,设置它的延迟,然后启动动画。 这是一些示例代码。 Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_down); animation.setStartOffset(750L); LayoutAnimationController controller = ...
  • 最简单的方法只是注意将视图添加到XML文件的顺序。 文件中的下降意味着在Z轴上更高。 编辑:这是在这里和这里在Android开发人员网站上记录。 (感谢@flightplanner) The easiest way is simply to pay attention to the order in which the Views are added to your XML file. Lower down in the file means higher up in the Z-axis. Edit: T ...
  • 首先, 关闭 animation库并使用ObjectAnimator库。 它更新,更有用100倍。 然后,使用AnimatorSet播放动画。 AnimatorSets可以按顺序播放动画或按顺序播放动画。 您可以创建动画,并使用AnimatorSet#Builter或AnimatorSet#playSequentially将其全部按顺序播放。 然后,不要担心垃圾收集和清理。 只要将它们从View中删除,垃圾收集器就会在它准备好时清除它们。 但是,您可以通过每次回收和重新使用ImageView来考虑更高效的策 ...
  • 你也可以使用带有layout_height =“match_parent”的LinearLayout和垂直方向来解决这个问题 您可以将ListView的layout_height设置为0dp并将layout_weight设置为1 然后它会尝试消耗LinearLayout中的所有剩余空间 I've discovered the solution to my problem but it did not lie where I first suspected after all. The problem was ...
  • 这更像是用于测量孩子的“深度优先”和用于实际绘图的“预先订购”。 父母将首先被抽出,而孩子则被放在父母的顶部。 It's more like "depth-first order" for measuring the children and "pre-order" for the actual drawing. The parent will be drawn first and the children stacked on top of the parent.
  • 从这个答案我决定研究ObjectAnimator类: Android ObjectAnimator 首先,我确实更改了两个按钮的ToggleButton ,一个名为go100,另一个名为go0,两者都从其currentPosition()滑动搜索条; 到100或0,这是因为他们有更好的逻辑使用,因为如果我没有强制它取消选中,执行动画后toggleButton将保持检查,并且无论哪种方式,它将是一个奇怪的UI行为。 两个按钮都在RelativeLayout之外,包含seekBar重新着色的彩色视图。 按钮xm ...
  • 我跟你做的一模一样。 我在Java活动中使用组合来实现我的活动中的功能共享。 我认为活动是“上下文”,而不是我的页面中被复制的部分。 因此,当我处于某个特定上下文(活动)中时,我会显示layout1,layout2和layout3以及特定参数,以及依赖于该活动的特定内容。 在另一个活动中,layout1,2或3可能不同,但它们在我的屏幕上始终具有相同的位置。 我通过视图使用组合:我的所有活动都有一个超类(称之为你想要的任何东西,比如ActivityWithCustomLayout ,它包含我作为类成员的所有 ...
  • 由于您没有发布布局,如果您可以将ViewPager和LinearLayout放在一个布局中(例如在RelativeLayout内),那么您可以为其设置动画。 Since you didn't post your layout, if you can put your ViewPager and LinearLayout in one layout, (for example inside a RelativeLayout) then you can animate that.
  • 我认为最好的方法是使用场景 ,但它需要Android 4.4.2(API级别19)或更高。 只需更改Layout的weight属性或尝试使用PercentRelativeLayout 。 您需要创建2个布局(场景)并在它们之间切换,并且您不必手动处理所有动画内容。 这里还有一个Android Transitions API向后兼容的库: Transitions Everywhere (如果你的项目的min SDK低于19)。 I think the best approach is to use Scene ...
  • 如何在没有一堆布尔变量的情况下以正确的顺序获取视图? 您需要某种状态控制才能使视图按顺序显示。 我会将视图构造/添加委托给一个控件类,该控件类将具有正确的视图所需的所有信息,并且无论加载器如何完成其工作,都按正确的顺序。 public class ViewDispatcher { public SparseArray mLoadStatuses = new SparseArray(); public SparseArray mDataCurso ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)