如何使用php上传文件到父目录
希望问题很简单,我有一个桌面应用程序,允许用户使用表单将文件上传到服务器,该表单将数据发送到网站上的受保护文件,如下所示。 Site_root/protected_folder/myfile.php 。如果您通常使用 php 文件上传命令,您将在“protected_folder”目录中操作,这是我不想要的。
我想将内容添加到根目录上的图像文件中,例如 Site_root/images/ ,您将如何在不进入 ftp 根目录的情况下执行此操作?
Hopefully easy question, I have a desktop application that allows the user to upload a file to a server using a form, the form sends the data to a protected file on the site like this. Site_root/protected_folder/myfile.php . If you use php file upload commands normally you'd be operating in the 'protected_folder' directory, which I don't want.
I want to add stuff to the images file on the root directory like this Site_root/images/ , how would you go about doing this without going the ftp root?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常的方法是调用 move_uploaded_file(),您可以根据自己的喜好设置目标路径。
$_FILES['tmp_name']
通常指向一个临时文件夹,它可能会被删除,恕不另行通知。The usual method is to call move_uploaded_file(), where you set the destination path to your liking. The file name in
$_FILES['tmp_name']
normally points to a temporary folder and it's subject to be removed without prior notice.您可以使用绝对路径,如
/path/to/images/
或使用相对路径,如../images/
假设您使用的是
move_uploaded_file< /code> 第二个参数采用您要上传到的目录。如果这篇文章没有,向您展示代码可能会有所帮助。
You can either use an absolute path like
/path/to/images/
or use a relative path like../images/
Assuming you're using
move_uploaded_file
the second paramater takes the directory that you wish to upload to. Perhaps showing you code may help if this post doesn't.move_uploaded_file()
将允许您相对于根目录放置上传,如果您只是以斜线开头,例如move_uploaded_file()
will allow you to place uploads relative to the root directory if you simply start your path with a slash like您可以简单地在路径中使用copy()和双点(../)来指定根目录来复制上传的文件。我也在用同样的您可能想要更改文件名,这样目录中就会出现唯一的文件名错误。扩展名也将相同。
//
you can simply use copy() and double dot (../) in path to specify root directory to copy the uploaded file. I'm using the same. You may want to change the file name so that there will be unique filename in the directory error will occur. extension will also be same.
//