简体   繁体   English

PHP bot分配上传路径

[英]PHP bot assigning upload path

I'm having an issue where the path of my file upload isn't being assigned to the correct folder. 我遇到的问题是我的文件上传路径没有分配到正确的文件夹。 It actually amends the file path to the file name of the file being uploaded. 它实际上修改了文件路径到正在上载的文件的文件名。 Weird right? 奇怪吧? Here's the code I'm working on... 这是我正在处理的代码......

<?php
      $allowed_filetypes = array('.mp4','.gif','.bmp','.png','.html','.psd','.zip','.xml','.css','.js',);
      $max_filesize = 5904288;
      $upload_path = 'video';

   $filename = $_FILES['userfile']['name'];
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

   if(!in_array($ext,$allowed_filetypes))
      die('Sorry, cannot take files over blankKB.');

   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('Sorry, cannot take files over blankKB.');

   if(!is_writable($upload_path))
     die('We are very sorry, a problem is occurring with the CHMOD  of this directory');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo ' Your file was uploaded successfully, view it <a href="file.php?file=' . $filename . '" target="_blank" title="Your File">here</a>';
      else
         echo 'Sorry, but there was an error during the file upload. Please try again.';
?> 

Here's what the file looks like after being uploaded, 这是上传后文件的样子,

videoHello.png videoHello.png

plus it doesn't upload the file to the directory I want it in, located at /video 加上它不会将文件上传到我想要的目录,位于/ video

When you write $upload_path . $filename 当你写$upload_path . $filename $upload_path . $filename you are only concatenating the two strings, which does indeed result in videoHello.png ; $upload_path . $filename你只是连接两个字符串,这确实导致videoHello.png ;

You should either concatenate your system's directory separator (On Unix based systems it's / ) 您应该连接系统的目录分隔符(在基于Unix的系统上它是/

$upload_path . '/' . $filename

or build the separator into your string $upload_path 或者将分隔符构建到字符串$upload_path

$upload_path = 'video/';

Though my final advice would be to use Absolute Paths like this: 虽然我最后的建议是使用像这样的绝对路径:

$upload_path = dirname(__FILE__) . '/video/';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM