我尝试使用以下代码将文件上传到服务器:
$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
$decodedData = base64_decode($data);
$name = uniqid(rand(), true) . '.jpg';
$fp = fopen('"imgdownload/'.$name.'"', 'wb');
fwrite($fp, $decodedData);
fclose($fp);
文件不会以这种方式上传,只有在我输入默认名称
时它才有效$fp = fopen("imgdownload/myfile", 'wb');
我收到了这个回复:
警告:fopen(" imgdownload / 1892454042e0263cf14.94958715.jpg"):无法打开流: C:\ xampp \ htdocs \ OrlenOla \中的参数无效api \ process.php 在 6 行
警告:fwrite()要求参数1为资源,布局在 C:\ xampp \ htdocs \ OrlenOla \ api \ process.php 中 7 < / b>
警告:fclose()要求参数1为资源,布局在 C:\ xampp \ htdocs \ OrlenOla \ api \ process.php 中 8 < / b>
我一遍又一遍地查看代码,但我不知道问题可能是什么。有人帮忙吗?
答案 0 :(得分:4)
错误说:
警告:fopen(&#34; imgdownload / 1892454042e0263cf14.94958715.jpg&#34;):失败 打开流:无效的参数 第6行的C:\ xampp \ htdocs \ OrlenOla \ api \ process.php
你有&#34;嵌套&#34;文件名中的引号。
$fp = fopen('"imgdownload/' . $name . '"', 'wb');
// ^ ^
// nested quotes should not be here
试试这个:
$fp = fopen('imgdownload/' . $name, 'wb');