[英]PHP fopen from windows to external unix server
I have a trouble with fopen(), the function returns "failed to open stream: No such file or directory" when i am trying to write file which is on unix server. 我在使用fopen()时遇到麻烦,当我尝试写入unix服务器上的文件时,该函数返回“无法打开流:没有这样的文件或目录”。 My PHP application is running on Windows.
我的PHP应用程序正在Windows上运行。
This is the code where I am using the fopen function : 这是我使用fopen函数的代码:
$path = "/212.120.15.80/tmp/NMJ.pdf"; //Path to unix server
$url = $_FILES [$fileElementName] ['tmp_name'];
$newfname = $path;
$file = fopen ( $url, "rb" );
if ($file) {
$newf = fopen ( $newfname, "wb" );
$fopen = $newf;
if ($newf) {
while ( ! feof ( $file ) ) {
fwrite ( $newf, fread ( $file, 1024 * 8 ), 1024 * 8 );
}
}
}
if ($fopen === false) {
$return_fopen = 'Fichier non téléchargé';
} else {
$return_fopen = 'Le fichier a été déposé sur le serveur';
}
if ($file) {
fclose ( $file );
}
if ($newf) {
fclose ( $newf );
}
I have write/read access on the tmp directory. 我对tmp目录具有写/读访问权限。
This code works when I am writing a file on a windows server with this path : "\\\\Example/share" 当我在Windows服务器上使用以下路径写入文件时,此代码有效:“ \\\\ Example / share”
First, it is worth checking if file exists before trying to load its content. 首先,值得在尝试加载文件内容之前检查文件是否存在。 Use
file_exists()
for this case. 在这种情况下,请使用
file_exists()
。 Then, your path is set to a local file. 然后,您的路径设置为本地文件。 Use something like
使用类似
$path = "http://212.120.15.80/tmp/NMJ.pdf"
I post my code for people who need it 我将代码发布给需要它的人
$docup = 'http://212.120.15.80'
$filename = $_FILES [$fileElementName] ['name'];
$ch = curl_init ( $docup );
curl_setopt ( $ch, CURLOPT_URL, $docup . "/uploadfilescript.php" );
curl_setopt ( $ch, CURLOPT_HEADER, false );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, array (
'file' => '@' . $url,
'filename' => $filename
) );
if (curl_exec ( $ch ) === FALSE) {
$return = 'Le fichier n\' a pas pu être téléchargé';
} else {
curl_exec ( $ch );
$return = 'Le fichier a été déposé sur le serveur';
}
curl_close ( $ch );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.