[英]PHP bot assigning upload path
我遇到的问题是我的文件上传路径没有分配到正确的文件夹。 它实际上修改了文件路径到正在上载的文件的文件名。 奇怪吧? 这是我正在处理的代码......
<?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.';
?>
这是上传后文件的样子,
videoHello.png
加上它不会将文件上传到我想要的目录,位于/ video
当你写$upload_path . $filename
$upload_path . $filename
你只是连接两个字符串,这确实导致videoHello.png
;
您应该连接系统的目录分隔符(在基于Unix的系统上它是/
)
$upload_path . '/' . $filename
或者将分隔符构建到字符串$upload_path
$upload_path = 'video/';
虽然我最后的建议是使用像这样的绝对路径:
$upload_path = dirname(__FILE__) . '/video/';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.