Page 1 of 1

make folder and copy files in client local drive from server

Posted: Thu Oct 29, 2009 2:38 am
by soumeek
Hi All,

I'm using PHP thru WAMP server 2 for a project.

I have some MP3 files stored on the server. Now logged in at some other client machine, I want to copy some files from the server machine to client machine thru the copy($source,$destination) function. For this i have to define a particular drive on the client machine and make a user defined directory (that client inputs in a form) where the files will be coppied. Using the mkdir($dir) function i want to create the directory and copy the files over there.

The whole process is running absolutey fine on the server machine (i.e, if i log on at the server and perform the action), but it is not working on remote client machine since the mkdir function cannot create a folder in a remote client file system.

Can i use the client IPadress to create a directory in the remote client machine? Or there is some other way to do this? Please help because I'm stuck with this problem for a number of days.

P.S.: I do not want a save request download diolog box for individual files, nor a zipped file download. I just want to copy the specified files in a specific defined folder in client machine.

My Code:

$folder=$_GET['folder']; // user defined folder inputed from a form

$dir="D:\\".$folder."/"; // Destination Directory to copy the files
if(!is_dir($dir))
{
mkdir($dir);
chmod($dir,0777);
}
$sqlDownloadTracks=mysql_query("select filename from tbldownloadtracks where requestWishListid='$requestWishListid'");
$copiedtracks=0;
$totaltracks=0;
while($rowDownloadTracks=mysql_fetch_array($sqlDownloadTracks))
{
$filename=$rowDownloadTracks['filename'];
$file = "controlp/uploads/".$filename;
$newfile = $dir.$filename;

if (copy($file, $newfile))
{
chmod($newfile,0777);
$copiedtracks++;
}
$totaltracks++;
}

Thanks and Regards in advance.

Re: make folder and copy files in client local drive from server

Posted: Thu Oct 29, 2009 4:19 am
by Mark Baker
Unless the client machine has a shared folder/drive that has been explicitly set up with write access for the server machine (using standard Windows shared folders or network drives), then the answer is no.
This isn't anything to do with PHP, it's all about network file sharing.

If the answer to the above is yes, then this is simply a network issue, and there are better alternatives than using web-interface PHP scripts to move files around within the network.

Re: make folder and copy files in client local drive from server

Posted: Thu Oct 29, 2009 4:54 am
by soumeek
Thanks. But can you kindly help me with the address i should give as the destination directory ?

For example, I want to copy the files at machine 192.168.1.17 in D: drive, which is a shared drive at the mentioned machine from my server.

Can you please tell what should i put as the destination address ? Is it something like "192.168.1.17\d\" or something else ?

Re: make folder and copy files in client local drive from server

Posted: Thu Oct 29, 2009 7:31 am
by Mark Baker
Assumption: your server is a Windows server.

If a folder/drive on the client machine is set up as a shared drive, with appropriate permissions, then it should be mapped on the server using the standard Windows network drive mapping features of Windows Explorer/Tools/Map Network Drive and given a Drive letter (e.g. D:).
If that is the case, then it can simply be referenced in your PHP code as D:\\

As far as I'm aware, it is not possible to do this network drive mapping through PHP itself.