尝试使用表单和PHP/IIS 7上传文件时,我得到以下消息:
PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0
我的形式:
<form action="acciones.php" id="form3" method="POST" enctype="multipart/form-data">
<input type="hidden" value="3" name="accion">
<input type="text" name="nombre" placeholder="Nombre">
<input type="file" name="imagen" accept="image/x-png, image/gif, image/jpeg" />
<input type="button" id="envio" class="button azul" value="Agregar" onclick="envios()">
</form>
我的PHP代码和参考:
$target = "/images/";
$target = $target . basename( $_FILES['imagen']['name']);
//This gets all the other information from the form
$name=$_POST['nombre'];
$pic=($_FILES['imagen']['name']);
//Writes the information to the database
$query = "INSERT INTO Playeras (Nombre, Ruta) VALUES ('$name', $pic')";
mysql_query($query, $conexion -> conn) or die("Error: ".mysql_error()) ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['imagen']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else
{
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
我已经为临时文件设置了路径:
upload_tmp_dir = "C:/Users/server/Pictures/tmp"
给予IIS_IUSRS和IUSRS完全控制权限。但每次都会出现错误。我不知道我做错了什么。如果有人能帮我,那就太好了。
成功了
改变upload_tmp_dir = "C:/Users/server/Pictures/tmp" to "C:'TEMP".
在C中创建文件夹TEMP并赋予权限。
我终于发现了,为什么这个错误实际上发生:
IUSR帐户(或php进程模拟的帐户,取决于您的身份验证设置)需要能够枚举upload_tmp_dir文件夹的父文件夹。
这个行为很奇怪,因为log或sessions文件夹不需要这个权限。
我的解决方案如下(使用上面帖子的路径):
- 创建文件夹"C:/Users/server/Pictures/tmp"
- 授予IUSR(或其他用户)对该文件夹的修改权限
- 创建文件夹"C:/Users/server/Pictures/tmp/uploads" 编辑php.ini: upload_tmp_dir ="C:/用户/服务器/照片/tmp/上传"
或者,您可以对父文件夹"C:/Users/server/Pictures/tmp"上的"this folder only"授予只读权限。在这种情况下,你不需要另一个子文件夹
最近在Laravel和Wordpress (php版本7.3)中工作时,我得到了这个错误"文件上传错误-无法在第0行创建未知的临时文件"
对我有效的解决方案是。希望这篇文章能帮助到任何遇到类似问题的人。
Laravel
- 在项目根目录下创建一个tmp目录。确保它有正确设置的写权限。 创建php.ini文件
- 在项目根目录下创建一个tmp目录。确保它有正确设置的写权限。在wp_admin文件夹中创建php.ini文件。在php.ini中添加以下行,以及其他ini设置。
upload_tmp_dir = on
upload_tmp_dir =/path/to/tmp/folder"
这里的路径将像/home/cpanel username/public_html/folder/project/tmp
注意:如果你在Laravel工作…如果您在存储文件夹中存储文件,请不要忘记链接存储文件夹。为此,在终端运行以下命令:
php artisan storage:link
这个帖子也添加了答案…警告:文件上传错误-无法在第0行