简体   繁体   English

PHP将'../folder/file.php'转换为url

[英]PHP convert '../folder/file.php' into url

So I'm working on a website currently on localhost. 所以我正在开发一个当前在localhost上的网站。 I'm testing an image uploader, and I have to generate an URL for the image to be displayed.. 我正在测试图像上传器,我必须为要显示的图像生成一个URL。

etc etc..
     // move the file to folder <- it works
    move_uploaded_file($_FILES["file"]["tmp_name"], '../../common/img/post-uploads/' . $name);

    // Generate response.
    $response = new StdClass;
    $response->link = MAINFOLDER . '/common/img/post-uploads/' . $name; // but I need an URL here..?:/
    echo stripslashes(json_encode($response));

As you see, when I move the uploaded file to path, it works like this "../../common/img/post-uploads" 如您所见,当我将上传的文件移动到路径时,它就像这样“../../common/img/post-uploads”

but at the end, I would like to get an URL.. so the final diplayed image would be like 但最后,我想得到一个URL ..所以最终的图像就像是

< img src="http://localhost/mysite/common/image/post-uploads/image.jpg"> <img src =“http://localhost/mysite/common/image/post-uploads/image.jpg”>

is it possible somehow? 有可能吗? like 喜欢

$response->link = convertThisToURL('../../common/img/post-uploads/' . $name);

? :/ :/

Since you show two ../ I would think that this item is outside of your domain. 由于你显示两个../我认为这个项目在你的域之外。 There isn't a way to do that unless the full link is inside the domain directory. 除非完整链接在域目录中,否则无法做到这一点。

Per your comment below then answer then would be a symbolic link. 根据你的评论,然后回答那将是一个符号链接。

ln -s /localhost/mysite/common/img/post-uploads /localhost/mysite/images 

For example. 例如。 then just post that nice new url without all that ../ stuff 然后发布那个漂亮的新网址,没有那些../的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM