第一个问题已经有一段时间了.基本上,我有一些代码(1)在实时环境中完美运行,(2)用于在我的家庭OSX环境中工作,但(3)现在不起作用.
HTML:
<form id="upload_form" action="php/upload_class_list.php" method="post" accept-charset="UTF-8" enctype="multipart/form-data" target="upload_target" >
<label>File:</label>
<input name="myfile" type="file" size="35" />
<input id="upload_submit" type="submit" value="Upload" />
<iframe id="upload_target" name="upload_target" style="width:0;height:0;border:0px solid #fff;"></iframe>
</form>
Run Code Online (Sandbox Code Playgroud)
PHP文件:
$destination_path = getcwd().DIRECTORY_SEPARATOR;
$result = 0;
$target_path = $destination_path . basename( $_FILES['myfile']['name']);
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
...
}
sleep(1);
?>
<script language="javascript" type="text/javascript">top.upload_class_list(<?php echo $result; ?>);</script>
Run Code Online (Sandbox Code Playgroud)
该脚本最后会触发,但PHP代码不会进入if(在本地开发环境中),因此$result保持为0.
它似乎没有拿起path要上传的文件; $destination_path指向PHP文件所在的文件夹,而不是指向找到该文件的位置.
当我改为Mountain Lion并重建PHP设置时,我认为我的本地环境可能已停止工作.
停止找到文件的缺失是什么?
让我强调一下:完全相同的代码在我的实时Hostmonster设置中运行良好,所以这是一个环境问题,我猜:)
谢谢.
if(@move_uploaded_file($ _ FILES ['myfile'] ['tmp_name'],$ target_path)){
...}停止找到文件的缺失是什么?
是什么让你认为问题是找到的文件?也许该文件是找到,但什么是失败的move......例如,由于Web服务器没有权限写入到target_path.
你可以查看:
$src = $_FILES['myfile']['tmp_name'];
$dst = $target_path;
if (!file_exists($src))
die("Okay, the file is actually not found");
if (!is_readable($src))
die("Very bad hosting juju. The file was uploaded but I can't read it?!?");
if (!is_writeable($destination_path))
die("As expected, you can't upload a file here. This is a good thing.");
@touch($dst);
if (!file_exists($dst))
die("So call me a Marine, the file SHOULD be writeable (which is not so good), and yet I could not write it! Perhaps disk full? User overquota? Some weird security setup?");
Run Code Online (Sandbox Code Playgroud)
这是一个好东西的原因是因为该目录包含可执行的PHP文件,如果有人可以在那里上传PHP文件,那么这将是一个主要的安全漏洞.
您可以留出另一个目录并使其可写(请记住放入.htaccess或其他系统以禁止从外部读取/执行访问).