Php “可能的原因”;无法打开流:没有这样的文件或目录";当文件确实存在时

Php “可能的原因”;无法打开流:没有这样的文件或目录";当文件确实存在时,php,Php,帖子移动到: 编辑:应该注意,此代码已经存在并运行了一段时间。我们将服务器配置从本地存储映像的单个邮件服务器切换到存储映像的共享NAS箱的负载平衡配置。然后php开始断断续续地说该文件不存在 99%的情况下,当你收到一个错误,说文件不存在,文件不存在,有打字错误或类似的错误 我们有一个.Net站点,可以将文件上载到临时位置。然后,我们向传入临时文件的php应用程序发送请求。然后php应用程序应该将文件从临时位置移动到永久位置 我们知道该文件存在,因为在.Net中,在向php应用程序发送请求之前,

帖子移动到:

编辑:应该注意,此代码已经存在并运行了一段时间。我们将服务器配置从本地存储映像的单个邮件服务器切换到存储映像的共享NAS箱的负载平衡配置。然后php开始断断续续地说该文件不存在

99%的情况下,当你收到一个错误,说文件不存在,文件不存在,有打字错误或类似的错误

我们有一个.Net站点,可以将文件上载到临时位置。然后,我们向传入临时文件的php应用程序发送请求。然后php应用程序应该将文件从临时位置移动到永久位置

我们知道该文件存在,因为在.Net中,在向php应用程序发送请求之前,我们在该文件上获取一个FileInfo对象,并检查FileInfo.exists

如果.Net确定该文件确实存在,它会将文件路径作为webrequest中的参数发送到php应用程序

但是,php应用程序会间歇性地(大约3次中有2次)出现以下错误:

“无法打开流:没有这样的文件或目录”

事实上,它是间歇性发生的,.Net表示它存在,我们可以导航到磁盘上的位置并进行验证,这表明是的,该文件确实存在

那么,为什么php会抛出这个异常,还有什么其他的可能性呢

.Net:

php:


是否每个文件都会发生这种情况?或者它在该文件上发生一次,然后PHP脚本可以在第二次尝试时打开它?每个文件都是一致的。这些文件是从facebook上传的图像。我们试着尝试接球,然后睡10秒钟,然后再试一次,但第二次总是不起作用。然而,下一次作业运行时,相同的facebook照片可能会很好地进入,而不会抛出错误。很可能是当您将文件名传递给php时,它被破坏了,php不会尝试访问与您在.net中访问的相同文件。还有,这是在哪个操作系统上,您如何知道(想象一些证据,并通过编辑您的问题来证明)文件名在PHP中没有被更改/与在.net中的文件名完全相同。@hakre,我同意这似乎是有可能的,尤其是PHP中的行与参数的编码混乱,那里可能有什么事情搞砸了。但是,如果编码是问题所在,那么错误是否会100%地发生?我们真的没有想到这是它,因为它间歇性地工作。文件路径的模式是………\~wtl\u upload\facebook\u 5794827594302.jpg
public void Save(string tempPath, string username, string password, bool deleteSrc, string merakController = "", string fileNamePrefix = "")
        {
            FileInfo fi = new FileInfo(tempPath);
            if (fi.Exists)
            {
                Name = (fileNamePrefix ?? string.Empty) + fi.Name;
                FileSize = fi.Length;
                TimeStamp = fi.LastWriteTimeUtc;
                string path = fi.FullName;

                if (string.IsNullOrEmpty(Type))
                    throw new Exception("Attachment Type not set");

                IceWarpGroupware_Http gwh = new IceWarpGroupware_Http(username, password);
                string parameters = string.Format("AttName={0}&AttType={1}&AttDesc={0}&AttSize={2}&AttTime={3}", Name, Type, FileSize, Time);
                bool result = gwh.AddAttachment(m_oid, path, parameters, string.Empty, merakController);

                if (!result)
                    throw new Exception("Unable to add attachment \"" + Name + "\"");

                try
                {
                    if (deleteSrc)
                        fi.Delete();
                }
                catch { }
            }
            //else
              //  throw new Exception("Temp file not found");
        }
public function AddAttachment($itemID, $src, $parameters, $value)
    {

        //base64 encode necessary parameters.
        $parameters64 = $this->getBase64(urldecode($parameters));
        $value64 = $this->getBase64($value);

        //Per the API documentation, ADD first, then LOCK, then move manually and then UNLOCK.
        $result = $this->FetchComObject()->FunctionCallBase64('AddAttachment', $this->gsid64, $this->getBase64($itemID), $parameters64, $value64);  //Add the attachment.
        $dest = $this->lockAttachment($this->gsid64, $this->getBase64($itemID), $result);  //Lock the attachment and get the destination path.

        //This is an enhanced version of the file copy routine for error handling if necessary.  Please let alone and commented out when not in use.
        // if (!copy($src, $dest))
        // {
            // if (isset($GLOBALS['php_errormsg']) && !empty($GLOBALS['php_errormsg']))
                // throw new RuntimeException($GLOBALS['php_errormsg']);
            // throw new RuntimeException("File copy failed with an undefined error. [".$src."]");
        // }

        $copySuccess = copy($src, $dest);  //Comment this line out if using the enhanced file copy above.
        //unlink($src);

        $success = $this->unlockAttachment($this->gsid64, $this->getBase64($itemID), $result);  //Unlock the attachment.
        if ($copySuccess == true)
            return true;
        return false;
    }