douxi3085 2012-12-16 21:20
浏览 33
已采纳

在PHP中的Ftp相对路径

I have a problem that I don't know how to solve. Let me explain it...

Directory structure:

-/public_html/lab/
-/public_html/lab/upload.php
-/public_html/lab/plugins/

I am really newbie with php+ftp, but I have the idea that FTP does not use "absolute root path" (/home/user/public_html/), instead it use "absolute user path" according to the user in question (/public_html), right?

Well, in the upload.php I have the code where the FTP class take a file temporally stored at the same folder where upload.php reside (/public_html/lab/) and then try yo move it to /public_html/lab/plugins/ folder.

FTP class receive a path where you want to move the file. But, I don't want to pass the path like absolute, I want to avoid this:

ftp->move('the-file.zip', '/public_html/lab/plugins/');

I would like to do something like this:

ftp->move('the-file.zip', '../plugins/');

But the code above looks like is not valid. So, how can I reproduce that result?

  • 写回答

2条回答 默认 最新

  • dsc7188 2012-12-16 21:42
    关注

    Rather than FTP which is designed for communication between two different hosts, consider moving the file via move_uploaded_file in upload.php:

    move_uploaded_file($_FILES['uploaded']['tmp_name'],'./plugins/'.$_FILES['uploaded']['name']);
    

    Once the file is uploaded via the PHP script, the temp file will be available in the _FILES superglobal under $_FILES[$inputFieldName]['tmp_name']. If you're using the example I gave, make sure to clean the "name" attribute before, since it will allow for client-side injection and leave a huge security hole in the application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染