Create folder on FTP server in directory where PHP script is

无人久伴 提交于 2019-12-09 21:21:21

问题


I use Current PHP version: 7.1.4 for Ionic2 application back-end.

I'm trying to create folder on my ftp server in the same directory, where directory.php located itself.

After link to http://site/php/directory.php echo:

Successfully created images

it creates images folder in user directory:

home/user/public_html/folder/php/uploads/

My directory.php located in php folder:

home/user/public_html/folder/php/uploads/

I want create images directory in exist uploads folder:

home/user/public_html/folder/php/uploads/images

uploads folder allows to create folder manually with FTP client tool

So what I have to do, to create it in uploads directory:

<?php
$ftp_server = "ftp_address";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "ftp_username", "ftp_password");

$dir = "images";

if (ftp_mkdir($ftp_conn, $dir))
  {
  echo "Successfully created $dir";
  }
else
  {
  echo "Error while creating $dir";
  }
ftp_close($ftp_conn);
?> 

回答1:


If you are creating a directory on the web server, the directory is local in a context of the PHP script. So do not use FTP functions, use functions for a local file system. Namely mkdir.

<?
$dir = "images";
if (mkdir($dir))
{
    echo "Successfully created $dir";
}
else
{
    echo "Error while creating $dir";
}

Most web servers execute PHP script with its actual location as a working directory. So a relative path like image will resolve relatively to a path of your PHP script.



来源:https://stackoverflow.com/questions/49899803/create-folder-on-ftp-server-in-directory-where-php-script-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!