上传文件和图像与mkdir特定的位置


Uploading Files and Images with mkdir specific location

我想把图像放在我的文件夹是从"$tablename"生成的,但未能将图像带到那里。如何保存上传的文件?

我喜欢从我的表单上传图片。

<input type="file" id="file" name="files" multiple />

无论我使用哪种上传技术都不适合使用,将文件保存到服务器上的特定位置。

如果你知道怎么做这个问题,请告诉我。

是mkdir代码。代码运行正常

 <?php
$tablename = "fisa";
$next_increment = 0;
$qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
$qShowStatusResult = mysql_query($qShowStatus) or die("" . mysql_error() . "" . $qShowStatus);
$row = mysql_fetch_assoc($qShowStatusResult);
$next_increment = $row['Auto_increment'];
echo "$next_increment";
$tablename = (string) ("$next_increment");
$year = date("Y");
$month = date("m");
$day = date("d");
If (!file_exists($year)) {
    $createsyear = mkdir("$year", 0777);
} else {
    If (!file_exists("$year/$month")) {
        $createsmonth = mkdir("$year/$month", 0777);
    } else {
        If (!file_exists("$year/$month/$day")) {
            $createsday = mkdir("$year/$month/$day", 0777);
        } else {
            If (!file_exists($year / $month / $day / $tablename)) {
                $createsday = mkdir("$year/$month/$day/$tablename", 0777);
            } else {
                //dada
            }
        }
    }
}
?>

谢谢。

这里我给出一个基本的文件上传的例子。

<form action="phpfilename.php" method="post" enctype="multipart/form-data" >
<input type="file" name="files" />
<input type="submit" name="submit" />
</form>
在PHP中

<?php 
    if(isset($_POST['submit']))
    {
    $path = $_FILES["files"]["name"];
    $target = "$year/$month/$day/$tablename/$path";  //this is your path where image need to be saved
    move_uploaded_file($_FILES["files"]["tmp_name"],  $target);
    }
?>

我解决了这个问题

 <?php 
    $tablename      = "fisa";
    $next_increment     = 0;
    $qShowStatus        = "SHOW TABLE STATUS LIKE '$tablename'";
    $qShowStatusResult  = mysql_query($qShowStatus) or die ( "" . mysql_error() . "" . $qShowStatus );
    $row = mysql_fetch_assoc($qShowStatusResult);
    $next_increment = $row['Auto_increment'];
    echo "$next_increment";
    $tablename = (string)("$next_increment");
    $year = date("Y");
    $month = date("m");
    $day = date("d");
    If(!file_exists($year)){
    $createsyear = mkdir("$year", 0777);
    }
    else
    {
    If(!file_exists("$year/$month")){
    $createsmonth = mkdir("$year/$month", 0777);
    }
    else
    {
    If(!file_exists("$year/$month/$day")){
    $createsday = mkdir("$year/$month/$day", 0777);
    }
    else
    {
    If(!file_exists($year/$month/$day/$tablename)){
    $createsday = mkdir("$year/$month/$day/$tablename/", 0777);

    $valid_formats = array("jpg", "png", "gif", "zip", "bmp");
    $max_file_size = 1024*100; //100 kb
    $target = "$year/$month/$day/$tablename/"; 
    $count = 0;
    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
        // Loop $_FILES to execute all files
        foreach ($_FILES['files']['name'] as $f => $name) {     
            if ($_FILES['files']['error'][$f] == 4) {
                continue; // Skip file if any error found
            }          
            if ($_FILES['files']['error'][$f] == 0) {              
                if ($_FILES['files']['size'][$f] > $max_file_size) {
                    $message[] = "$name is too large!.";
                    continue; // Skip large files
                }
                elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                    $message[] = "$name is not a valid format";
                    continue; // Skip invalid file formats
                }
                else{ // No error found! Move uploaded files 
                    if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $target.$name)) {
                        $count++; // Number of successfully uploaded files
                    }
                }
            }
        }
    }
    }
    else
    {
    }
    }
    }

    }

    ?>