ftp_get parent name and just some subfolders - php

i use ftp_get to download my ftp files from my server to my laptop. and i want to download just somes dirs and files but under the parent name
for example i have a folder public_html contains 3 folder A and B and C. i want to get just the A Folder but also the parent which is public_html im looking for this result : public_html/A. i mean i want to download the parent/child
this is my code :
ftp_get($conn_id, "public_html/A", "public_html/A", FTP_BINARY);
i get only the sub folder A

Related

How to run files from every folder in PHP?

I have a main folder project name socialNetwork. In this folder, I have 3 folder name application, database, and view. folder view has 2 folders views and page. These folders have files php. Now if I want to run the file from view folder I have to be inPSC:\PhpstormProject\socialNetwork\> and use php view/page/profile.php. If I run PSC:\PhpstormProject\socialNetwork\view> and use php page/profile.php show me the error Could not open input file: page/profile.php. So what can I do to run files from every folder, because now I can only from the main project folder?

Create folder outside public_html to upload files

I creating script and I need to let users upload files (images) . and for security reasons I want to make file folder outside public_html.
But my problem is maybe my potential customers may have different folders structure in their servers.
So my question is : There is a way in php to go back one folder before public_html ?
Another possible case if my client put script file in directory like that public_html/demo/ , so in that case I need to go 2 folders back.
I try to use $_SERVER["DOCUMENT_ROOT"] but it give the public server directory.
any help or suggestion will be helpfull. thank you
If the php user has the permission to do so, you should be able to include/write files to a directory using a relative path for example:
include("../test.php");
Likewise if you had a directory which was writable by the php user you should be able to create files in that directory also using a relative path:
$ cat test1.php
<?php
$file = fopen("../test.php", "w");
fwrite($file, "Hello World. Testing!\n");
fclose($file);
include("../test.php");
$ php test1.php
Hello World. Testing!

zip renameName function is not renaming files in sub directories

I am compressing directories and sub directories using PHP zip library. Everything is working fine except renaming files under sub directories. This code is renaming the files successfully in root directory
$zip->addFromString(basename($file), $download_file);
$zip->renameName(basename($file), 'nicename.mp3');
but it is not renaming files in sub directory. Can anybody assist please ?
I have taken this code from Here

how to get all media files from folder with sub folders in server using php

I have get the media files from server folder. The server folder contains multiple sub folder and each sub folder contains some media files. I need get the all media files from each folders. how can i get it..
Read about PHP's readdir.
you can look down on user-comments, there are a few functions there you can use.

How do I upload images to the correct path in PHP?

I have a website with the following path for images: domain.com/images
I am using a PHP script in the back-end to upload images to that folder BUT the page that lets me upload images to that path above is located at domain.com/administration/upload.php.
So now when I am using a script to write to domain.com/images this is what I am using:
$newname="/images/".$image_name;
For some reason it won't write to that folder and I get no errors and here's the link from where I got the script:
http://www.reconn.us/content/view/30/51/
What do I have to do to make it write to that domain.com/images path from domain.com/administration/upload.php?
You have to distinguish virtual server path from filesystem path.
There are no /images/ directory on your disk
but something like /home/www/user/public_html/images/
so, change your code to
$newname = $_SERVER['DOCUMENT_ROOT']."/images/".$image_name;
and it should be okay
You can try this for the exact path to folder
/* $_SERVER['DOCUMENT_ROOT'] will point to your root folder( www ) and after that your website folder name and them images folder name */
$newname = $_SERVER['DOCUMENT_ROOT']."/folder name/".$image_name;

Categories