如何找出在php上传图片的相对路径?

时间:2012-05-03 10:33:23

标签: php relative-path image-uploading

我有一个问题需要找出相对路径 将图像上传到其他目录

目标目录

htdocs/dt3/tadi/adm/dim/dim_images/tadi_user_images/

源目录

htdocs/dt3/tadi/adm/cbt/uploadfile.php

uploadfile.php

<html>
    <form method="post"enctype="multipart/form-data">
        <input type="file" name="fileimg1" ><input type="submit" name="upload">
    </form>
</html>


<?php
    $dirname = "/dt3/tadi/adm/dim/dim_images/tadi_user_images/";    

    $of = $_FILES['fileimg1']['name'];
    $ext = pathinfo($of, PATHINFO_EXTENSION);

    $changename3 = time() * 24 * 60;
    $image_name3 = "timage_" . $changename3 . "." . $ext;

    $final_pathdir = $dirname . $image_name3;
    $suc = move_uploaded_file($_FILES['fileimg1']['tmp_name'], $final_pathdir);

    if ($suc > 0) 
    {
        echo "Image uploaded successfully"; 
    } 
    else 
    {
        echo "Error : " . $_FILES['filimg1']['error'];
    }
?>  

我尝试了一些路径,我没有得到任何解决方案。
如何将图像上传到该路径?

htdocs/dt3/tadi/adm/dim/dim_images/tadi_user_images/

仅限相对路径。

1 个答案:

答案 0 :(得分:6)

我相信你可以做到

$dirname = dirname(__FILE__)."/../dim/dim_images/tadi_user_images/"