PHP - mkdir文件错误

时间:2017-07-31 03:28:17

标签: php file

当我将文件提交到我的文件目录中时,我会收到很多错误,例如

  

(!)警告:mkdir():第38行的C:\ wamp64 \ www \ MT \ directory.php中没有这样的文件或目录

     

(!)警告:move_uploaded_file(devPacks / peopl39e_8503_cheese / 0kk / 1501471127_adc9ebd871a68b573fd928ebff5bb54b.png):无法打开流:第40行的C:\ wamp64 \ www \ MT \ directory.php中没有此类文件或目录

来自目录。我认为问题在于这行代码

$dir = "devPacks/" .$fullname."_".$userid."_".$username."/".$packname;

因为当我排除" $ packname"像这样

$dir = "devPacks/" .$fullname."_".$userid."_".$username."/".$packnames;
  

注意我添加了一个" s"发送包名*,我得到了这个

     

(!)注意:未定义的变量:packnames in   第35行的C:\ wamp64 \ www \ MT \ directory.php

当我回显目录时,我得到了这个" devPacks / peopl39e_8503_cheese / &#34 ;.所以我不确定发生了什么,但这是我的代码。

PHP

<?php
if($_SERVER['REQUEST_METHOD'] =="POST"){
    $currentDirectory = getcwd();
    $userid = "8503";
    $fullname = "peopl39e";
    $username = "cheese";
    $packname = "0kk";
    foreach($_FILES['file']['tmp_name'] as $key => $error){
        if ($error != UPLOAD_ERR_OK) {
            $errors[] = $_FILES['file']['name'][$key] . ' was not uploaded.';
            continue;
        }
        $file_tmp = file_get_contents($_FILES['file']['tmp_name'][$key]);
        //keep only A-Z and 0-9 and everything else KILL
        $file_name = preg_replace("/[^a-z0-9\.]/", "_", strtolower($_FILES['file']['name'][$key]));
        $file_name = strtotime("now")."_".$file_name;
        $allowed =  array('gif','png' ,'jpg');
        $ext = pathinfo($file_name, PATHINFO_EXTENSION);
        if(!in_array($ext,$allowed) ) {
            die('error');
        }
        $dir = "devPacks/" .$fullname."_".$userid."_".$username."/".$packname;
        if(is_dir($dir)==false){
            mkdir($dir, 0777);
        }
        if(!move_uploaded_file($_FILES['file']['tmp_name'][$key],$dir.'/'.$file_name)){
            die("File didn't send!");
        }
    }
    echo $dir;
}
?>

1 个答案:

答案 0 :(得分:1)

尝试

上传文件路径import React from 'react'; const Home = () => ( <div> <h1>HOME PAGE</h1> </div> ); export default Home;