无法将上传的文件移动到随机生成的文件夹中

时间:2015-06-27 21:56:33

标签: php

在社交网站上工作,该网站允许用户将默认照片上传到随机生成的文件夹中。一切正常,直到功能移动上传文件。谁能告诉我我做错了什么?托管在bluehost上。

<?php
  if(isset($_FILES['listingpic'])){
    if(@$_FILES['listingpic']['type']=="image/jpeg"||@$_FILES['listingpic']['type']=="image/png"||@$_FILES['listingpic']['type']=="image/gif"){
        if(@$_FILES['listingpic']['size']<1048576){
            $chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            $rand_dir_name = substr (str_shuffle($chars), 0, 15);
            echo "new directory: ".$rand_dir_name;
            mkdir("userdata/listingpics/$rand_dir_name/") or die("directory error");
            move_uploaded_file(@$_FILES['listingpic']['tmp_name'], "userdata/listingpics/".$_FILES['listingname']['name']) or die("Failed to move file.");
        } else echo "File must not exceed 1MB.";
    } else echo "File must be a JPEG, PNG, or GIF image."; 
  } else echo "Not set.";
?>

1 个答案:

答案 0 :(得分:3)

left join应该读为
"userdata/listingpics/".$_FILES['listingname']

另外,"userdata/listingpics/$rand_dir_name/".$_FILES['listingname']
mkdir("userdata/listingpics/$rand_dir_name/")没有斜杠。

您没有在其中加入mkdir("userdata/listingpics/$rand_dir_name")