doubingguan3425 2014-09-13 00:52
浏览 36
已采纳

上传文件是前缀指定文件夹的名称,最终在该文件夹之外

Haven't found anything that quite fits what is happening to me, but maybe you do. You should know that I'm in local environment, using apache & php in MAMP.

I am uploading a file image to a folder (uploads), which lies in the root folder (htdocs). Problem is that when, let's say, capybara.jpg gets uploaded, it ends up as uploadscapybara.jpg outside of the uploads folder.

My php is below

$name = $_FILES['image']['name'];
//$size = $_FILES['image']['size'];
//$type = $_FILES['image']['type'];

$tmp_name = $_FILES['image']['tmp_name'];

if (isset($name)) {
if (!empty($name)) {

$location = 'uploads';

if (move_uploaded_file($tmp_name, $location.$name)) {
echo 'uploaded!';
} 
} else {
echo 'Please choose a file';
}
}

I get no warning of any kind as the php is above, but still have the problem. if I try adding a slash to uploads, writing $location = '/uploads' I will get

Warning: move_uploaded_file(/uploadsCapybara.jpg): failed to open stream: Permission denied in   /Applications/MAMP/htdocs/uploadfile.php on line 22

Warning: move_uploaded_file(): Unable to move '/Applications/MAMP/tmp/php/phpCTLZgH' to '/uploadsCapybara.jpg' in

I went into the folder, clicked Get Info, and changed Privelege to Read and Write for superuser and admin. I wrote an alias mod which is what gets the file to upload at all and then wrote a directory for that <Directory "/Applications/MAMP/uploads"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>,

And I also wrote include_path for the folder. ".:/Applications/MAMP/bin/php/php5.5.14/lib/php:/Applications/MAMP/htdocs/uploads"

So from all the things that I have read, and I've tried them, nothing is working. something in my syntax must be off??? what aren't I getting??

  • 写回答

1条回答 默认 最新

  • duanqia9034 2014-09-13 01:02
    关注

    You forgot a trailing slash in your location value.

    $location = 'uploads/';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题