Page 1 of 1
save file to computer on local network
Posted: Thu Mar 14, 2013 6:40 pm
by inosent1
using the basic html code to locate a file, the user then submits and uploads the file via php
Code: Select all
$ts = date('mdyh_m_s');
$file_id = mysql_real_escape_string($_POST['file_id']);
$orig_name = $_FILES["file"]["name"];
$filen = explode(".", $_FILES["file"]["name"]);
$ext = $filen[1];
$fname = $filen[0];
$file_name = $fname . '_' . $ts . '_' . $file_id . '.' .$ext;
move_uploaded_file($_FILES["file"]["tmp_name"], "efiles/" . $file_name);
that code uploads to the server.
i am looking for code to upload to a computer on a local network:
Code: Select all
move_uploaded_file($_FILES["file"]["tmp_name"], "\\server_name\\folder1\folder2\folder3\" . $file_name);
in other words, i want the file moved to 2 locations -- the server online, and a local PC on the network; i also want to direct the code to store the file in the correct folder in the local machine
TIA
Re: save file to computer on local network
Posted: Thu Mar 14, 2013 7:46 pm
by requinix
Running on Windows, right?
You can do it the same way as if it's a local destination (same code, "\\machine\path" filename) but you do have to consider permissions. Like IIS runs as one user who typically doesn't have access to... well, practically anything. Apache is looser on the permissions because it's probably running under a general system-level account (like NETWORK_SERVICE).
Don't forget to double up your backslashes!
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 1:36 pm
by inosent1
Code: Select all
move_uploaded_file($_FILES["file"]["tmp_name"], "\\\\Computer_name\\Users\\Public\\" . $file_name);
i tried this and what it did was upload the file to the same folder as the upload.php page and named it:
\\Computer_name\Users\Public\123.jpg
so it didnt even try to move it to the local PC on the network
what i am trying to do is locate a file using web form, and instead of saving it to a folder on the remote server (easy), save it to a folder on a local computer on the network.
thanks for the reply
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 2:00 pm
by requinix
Are you running on Windows? Filenames cannot possibly contain backslashes on Windows...
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 2:31 pm
by inosent1
right, that is the point ...
move_uploaded_file($_FILES["file"]["tmp_name"], "[location]" . $file_name);
\\\\Computer_name\\Users\\Public\\" was supposed to be where the file is supposed to be saved to, the folder location, with (in this example) the file name as '123.jpg'
after i ran the code i looked in \\Computer_name\Users\Public\ for the file 123.jpg, but instead of saving the file to that local destination with the above code, it just uploaded it to the remote server and interpreted my attempt to define the local folder location as part of the file name
iow '\\Computer_name\Users\Public\123.jpg' became the name of the file uploaded to the server, instead of '123.jpg' being saved to '\\Computer_name\Users\Public\' on the local hard drive.
just wondering how to save the file to the local HD, if that is possible
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 3:10 pm
by requinix
Are you saying you want the file saved to [drive]:\Computer_name\Users\Public\123.jpg? Because you keep saying "local destination" and "local hard drive". That structure with the leading "\\" means a remote path (Computer_name machine, Users share, \Public folder), not a local path.
Or are you saying the file is located in some directory and the file itself (not the path to the file) is "\\Computer_name\Users\Public\123.jpg"?
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 8:12 pm
by inosent1
thanks for the reply.
the computer i need to save the files to is part of the network. it is on the network
so technically the folder where the file is to be stored is not on my machine, it is on another PC in an adjoining office, and it has its own unique name.
eg: \\[Computer_name of PC on the network my PC has full access to]\Users\Public\
what i meant by 'local' is not uploaded to a remote host (the company's website), but instead, saved to one of the computers here. that way we have one operation to save the file to a remote and 'local' destination, theoretically at the same time.
i am just trying to figure out how to save the file to the computer here, on the network here at the office using PHP.
Re: save file to computer on local network
Posted: Fri Mar 15, 2013 10:13 pm
by requinix
Alright, then looking back a couple posts:
inosent1 wrote:after i ran the code i looked in \\Computer_name\Users\Public\ for the file 123.jpg, but instead of saving the file to that local destination with the above code, it just uploaded it to the remote server and interpreted my attempt to define the local folder location as part of the file name
inosent1 wrote:what it did was upload the file to the same folder as the upload.php page and named it:
\\Computer_name\Users\Public\123.jpg
Both of those say that the file was literally named "\\Computer_name\Users\Public\123.jpg". With backslashes. That's what I'm saying isn't possible
on a Windows machine. I haven't gotten a straight answer yet so I'll ask again:
is this code running on a Windows machine?
If so then please clarify what you meant in those two posts. If not then that totally explains everything.
Re: save file to computer on local network
Posted: Wed Mar 27, 2013 6:23 pm
by inosent1
sorry it took so long to reply
ok, just as an example, yes, i am on a windows machine, and every PC on the network is to.
when i go to the address bar to get a local file, this is what the link looks like
[url]
C:\Users\pc1\Desktop\folder1\folder2\folder3\folder4\progam.exe
[/url]
but the computer i want to use to store the files is on a local network, and an example of what that address looks like is this:
\\Networked_Computer_name\folder1\fold ... doc.pdf
that is exactly what it looks like, backslashes and all.
now, the code to perform this task is (hopefully) is php code in a php page uploaded to a remote server.
the company has a remote host for its website and data management system, and for files, it stores them on a computer on a local network
so i need the php page uploaded to the online server to be able to pull up a save as dialogue box on the users machine, with the file saves to the right folder on the local machine.
there are no issues with permissions. i am looking at the local machine, it is in my office, right next to my desk.
so, the concept is for the user to go online to a web page uploaded to the remote server, hosted by jomamma.com, click on a button on that page and have the php code hit the users local machine, pop up from the local machine a 'Save As' dialogue box, where the location of where the file is to be saved is pre-determined by the appropriate syntax
is that clearer?
Re: save file to computer on local network
Posted: Wed Mar 27, 2013 8:16 pm
by requinix
Yes, much clearer.
It's not possible. You cannot give anything except for the name of the file. No predefined path, no suggested location.
You could, however, make the PHP script save the file to that location, provided it's accessible and PHP has permission to write to it. Which it sounds like it is because the server is on the same network (if I understand that correctly) and the permission thing is... well, probably possible, depends.
Re: save file to computer on local network
Posted: Mon Apr 01, 2013 12:57 pm
by inosent1
thanks for the reply
the better question is, how to save a file to a local server - i.e. one on a local network (as compared to remote server, eg mysite.com hosted by somebody.com), using a PHP script
TIA