函数tmpfile()会真的创建一个linux临时文件tmp不足的文件吗

为什么上传了文件之后,在临时文件夹中找不到tmp文件?_php吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:121,875贴子:
为什么上传了文件之后,在临时文件夹中找不到tmp文件?收藏
tmp目录下万年只有这3个玩意儿:
上市公司「达内」全新php开发课程,以实战为主线,穿插php理论教学.取证+就业一步到位,14年经验,20W毕业学员,用实力说话!名企直通班招生中,88天月薪即可月薪上万,免费试听!
这里我没有调用move_uploaded_file()函数,只是上传了文件。
php脚本结束后,tmp文件也会删除,你尝试着再中间,sleep(10);一下试试,你就能看到了。
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或天极传媒:天极网全国分站
您现在的位置: &&
创建临时文件
VB爱好者 00:00
  在Visual Basic中开发程序时,可能会需要在磁盘上创建一个临时目录或文件,本文介绍如何在Visual Basic 4.0中创建临时文件。
  使用GetTempFileName函数
  Windows API函数中的GetTempFileName函数可以用来在指定的磁盘驱动器上创建一个新的文件。尽管所创建的文件是一个临时文件, 但不再需要它的时候,程序员还是需要将它从磁盘上物理地删除掉。
  要在VB中使用GetTempFileName函数,必须将如下声明语句包含在程序中(请注意该声明语句需要书写在一行内):
  Private Declare Function GetTempFileName Lib"kernel32" A lias"GetTempFile
NameA" (ByVal lpszPath As String, ByVal lpP refixString As String, ByVal wUni
que As Long, ByVal lpTempF ileName As String) As Long
  该GetTempFileName函数需要4个参数:
  第一个参数是希望创建新文件的驱动器和/或路径的名称,在下面 的样例程序中,新文件创建在驱动器的根目录下。
  第二个参数是指派给文件名称的前缀。如果将该前缀指定为"TES T",则函数将把创建的新文件名称的前四个字符设置为"TEST",即"TES T*.TMP"。
  第三个参数应该被设置为0,告诉该函数为文件名称自动产生随机 号码。该随机号码会被添加到前缀字符的后面,以产生一个独特而且 完整的文件名称。
  第四个参数是一个字符串缓存,它至少要有256个字符的长度,以 存放临时文件的名称。
  在调用该函数之后,新文件创建在指定的磁盘上。这里重申一下, 当退出应用程序时,必须物理地将该文件从磁盘上删除。
  样例程序
  该程序显示了如何在VB应用程序中创建一个临时文件。
  1.在Visual Basic中开始一个新的工程,采用缺省的方法建立For m1。
  2.将如下声明语句添加到Form1的声明部分中(请注意该声明 语句需要被书写在一行内):
  Private Declare Function GetTempFileName Lib"kernel32" A lias"GetTempFile
NameA"(ByVal lpszPath As String, ByVal lpPr efixString As String, ByVal wUniq
ue As Long, ByVal lpTempFi leName As String) As Long
  3.将如下代码添加到Form1的Form_Load事件中:
  Private Sub Form_Load()
    Text1.TEXT = ""
  End Sub
  4.在Form1上添加一个文本框控件,采用缺省的方法建立Text1。
  5.在For
咸砑右桓雒畎磁タ丶?采用缺省的方法建立Comman d1。
  6.将如下代码添加到Command1的单击事件中:
  Private Sub Command1_Click()
   Dim FilePrefix As String
   Dim NewFile As String * 256
   FilePrefix = "TEST"
   NewFile = GetTempName(FilePrefix)
   Text1.TEXT = NewFile
  End Sub
  7.创建一个新的名为GetTempName的函数,将如下代码添加到该函 数中:
  Private Function GetTempName(TmpFilePrefix As String) As String
   Dim TempFileName As String * 256
   Dim X As Long
   Dim DriveName As String
   DriveName = "c:"
   X = GetTempFileName(DriveName, TmpFilePrefix, 0, TempFi leName)
   GetTempName = Left$(TempFileName, InStr(TempFileName, Ch r(0)) - 1)
  End Function
  按下F5键,执行本样例程序.单击命令按钮,在驱动器C的根目录下创建一个新的临时文件.该新创建的文件的名称被显示在文本框控件中.
(作者:请作者和我们联系责任编辑:)
欢迎在新浪微博上关注我们
笔记本手机数码家电PHP tmpfile() 函数
定义和用法
tmpfile() 函数以读写(w+)模式创建一个具有唯一文件名的临时文件。
提示和注释
注释:临时文件会在文件关闭后(用 fclose())或当脚本结束后自动被删除。
提示:参见 tempnam()。
$temp = tmpfile();
fwrite($temp, "Testing, testing.");
//Rewind to the start of file
rewind($temp);
//Read 1k from file
echo fread($temp,1024);
//This removes the file
fclose($temp);
上面的代码将输出:
Testing, testing.
反馈内容(*必填)
截图标记颜色
联系方式(邮箱)
联系邮箱:
投稿页面:
记住登录状态
重复输入密码& 建立一个临时文件
PHP tmpfile 建立一个临时文件
tmpfile & 建立一个临时文件
resource tmpfile
详细信息请参考系统手册中的
tmpfile(3) 函数,以及
stdio.h 头文件。
Example #1 tmpfile() 例子
&?php$temp&=&tmpfile();fwrite($temp,&"writing&to&tempfile");fseek($temp,&0);echo&fread($temp,&1024);fclose($temp);&//&this&removes&the&file?&
以上例程会输出:
writing to tempfile
PHP tmpfile note #1
A clean method to use temporary file:
$tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
file_put_contents($tmp, 'hello');
echo file_get_contents($tmp);
without need to fclose the tmp file, it will be deleted while the php ends.
PHP tmpfile note #2
Remember, that open_basedir affects this function. You will get an error:
Warning: tmpfile() [function.tmpfile]: open_basedir restriction in effect. File(/var/tmp) is not within the allowed path(s): ....blablabla =)
PHP tmpfile note #3
No, the fseek() is necessary - after writing to the file, the file pointer (I'll use "file pointer" to refer to the current position in the file, the thing you change with fseek()) is at the end of the file, and reading at the end of the file gives you EOF right away, which manifests itself as an empty upload.
Where you might be getting confused is in some systems' requirement that one seek or flush between reading and writing the same file.& fflush() satisfies that prerequisite, but it doesn't do anything about the file pointer, and in this case the file pointer needs moving.
PHP tmpfile note #4
I am fairly sure that the seek just flushes the data from the memory buffers to the file.& fflush() should give you the same effect.
PHP tmpfile note #5
By the way, this function is really useful for libcurl's CURLOPT_PUT feature if what you're trying to PUT is a string.&& For example:
$ch = curl_init();
$putString = "Hello, world!";
$putData = tmpfile();
fwrite($putData, $putString);
fseek($putData, 0);
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $putData);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putString));
$result = curl_exec($ch);
fclose($putData);
curl_close($ch);
PHP tmpfile note #6
fseek() is important because if you forget about it you will upload empty file...
i had sth like that ^_^
PHP tmpfile note #7
I found this function useful when uploading a file through FTP. One of the files I was uploading was input from a textarea on the previous page, so really there was no "file" to upload, this solved the problem nicely:
&&& $fSetup = tmpfile();
&&& fwrite($fSetup,$setup);
&&& fseek($fSetup,0);
&&& if (!ftp_fput($ftp,"inc/setup.inc",$fSetup,FTP_ASCII)) {
&& & && echo "&br /&&i&Setup file NOT inserted&/i&&br /&&br /&";
&&& fclose($fSetup);
The $setup variable is the contents of the textarea.
And I'm not sure if you need the fseek($temp,0); in there either, just leave it unless you know it doesn't effect it.
PHPFilesystem - 函数

我要回帖

更多关于 tmp临时文件 的文章

 

随机推荐