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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭