transfer file from path to path in ftp using php - php

Here is my prob in Brief.
I know how to upload a file to server using FTP with programming language PHP.
But is that possible to transfer files from one directory to another directory. In the same server....
I have the two paths of the directorys...
Any idea how?

Related

Move file to specific path in PHP

I'm building a web app with MySQL/PHP/JS.
I have files in htdocs/mywebsite/foo/foo1/ path. Example:
htdocs/mywebsite/foo/foo1/image.png
I need to move these files to:
htdocs/mywebsite/foo3/image.png
Any help?
There is a rename() function in PHP that will just rename a file or will move it from one directory to another if the from and to directories are different.
<?php
rename("htdocs/mywebsite/foo/foo1/image.png",
"htdocs/mywebsite/foo3/image.png");
?>
In order to move files on a fileserver you need to use FTP (File Transfer Protocol). Programs like FileZilla could help you with that. A proper webhost should also have a FTP client on the control panel.
Using FileZilla:
Login to your webserver, simply cut and paste or drag and drop.
if you need to simple move all files from FTP using FTP tools like filezila or many other FTP software.
second from putty use mv command to move file.

Upload local file to FTP server using PHP

I have searched everywhere but didn't got a perfect answer.
I am using WAMP to run PHP on local machine. I have an tag to accept file from local machine and have to upload this to FTP server.
My code is working perfectly fine but only if file is present directly on base path i.e. /wamp/www/ but if I pick file from desktop to upload, it didn't actually pass path of file to action php file instead just pass on file name.
Is there a way to achieve this functionality?
Thanks
Saransh

how to save uploaded file in another server?

I have tow servers for my web site. first, for database and php files. the second, for save useres' uploaded files.
So, if I uploade a file in server-1 xxx.com. how could i save it in server-2 yyy.com??
if you want two servers to be exact clones (contianing same files) you can run a rsync script after your first uplaod has completed. Its very easy and best of you don't have to specify files.
Lets say you want to transfer all files in directory /files/ to server2 in directory /files/2/ You can run this :
rsync /files/ yyy.com:~/files/2/
If you ONLY want specific files (extensions) to be synced, you can do this:
rsync /files/*.mp3 yyy.com:~/files/2/
The above will move ONLY MP3.
You can simply upload one file from server 1 to the server 2 using PHP's FTP functions.
See code example here: http://www.jonasjohn.de/snippets/php/ftp-example.htm
Use shared storage (SAN). Or SMB shares if on Windows. Or NFS if on Unix. Or scp (ssh) with public key authentication if on Unix.
An ugly way I used once was to pass via cURL and FTP commands
Of you course, you need to have access to your server-2 FTP...

php uploading file?

I just want to know that if I am using move_uploaded_file function and use two argument first as the name of file and second as the destination.
Normally I have uploaded many files with class uploader but now I want to give the destination as http://www.example.com/testing/
Although I have given 777 permission to this folder but when I try to execute the upload code error came
Destination directory can't be created. Can't carry on a process.
How can I upload the file local to server using php code?
If you are passing http://www.mydomain.com/testing/ as the target, this is wrong.
You can't just upload files to servers via HTTP, you only can do that to local folders, can you paste the exact code so we can know better what are you trying to do?
move_uploaded_file is a server-side function, so all the paths should be specified server side.
If your upload.php (i'm assuming the filename) is in the main directory of the website www.mydomain.com/ which is probably /home/youruser/public_html/ then you can specify the destination as simply "testing/"
If your upload file is in some nested directory, then it may work better to specify the full destination path:
/home/youruser/public_html/testing
good luck

Which location to save uploaded files

I am using php and i have written codes to allow a user upload a file. For testing purposes, i have saved the file to D:/final/temp/test.xls. Then i generate another file and save it to the same location. This file can be downloaded by the user.
But if an actual user would be using my application,
where should the location point to? Thanks!
You need to upload the file to a directory which is being served by your web server. You have 3 options:
Find the directory where your PHP files are being served and save the files to that location, or a directory underneath.
In your web server config, map the D:/final/temp/ directory to a website or virtual directory.
Create a PHP file that reads the file from the D:/final/temp directory and serves it to the end user. This option is trickier to setup and has more gotchas in terms of performance.
The location which you upload to needs to have write permissions, and the web server also needs to be able to read files from this location.

Categories