我想从我的Android应用程序上传文件。第一次成功发生但第二次如果我想替换文件则不会做任何事情。
string json = @"<what you have above>";
MyPoco = json.FromJson<MyPoco>(json);
答案 0 :(得分:0)
您可以尝试在删除现有文件之前更改文件权限(如果允许您的www用户执行此操作)
<?php
$basename = basename($_FILES['uploaded_imagen']['name']);
//todo: (play safe) $basename = hash('sha256', $basename) . '.EXT';
$target_file = 'usuario/' . $basename;
if(file_exists($target_file))
{
chmod($target_file,0755); //change perms if possible
unlink($target_file); //remove the file
}
if(move_uploaded_file($_FILES['uploaded_imagen']['tmp_name'], $target_file))
{
echo "<P>FILE UPLOADED TO: $target_file</P>";
}
else
{
echo "<P>MOVE UPLOADED FILE FAILED!</P>";
print_r(error_get_last());
}
或者 - 只需更改目标目录的权限(在首先找出服务器运行的www-user之后):
ps aux | egrep '(apache|httpd)'
chown www-user:www-group '/path/to/files'
chmod 0700 '/path/to/files'