Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving file location 1

Status
Not open for further replies.

sdalgleish

Programmer
Feb 4, 2005
4
GB
I'm looking to create a little app that takes in information about a file then uses a form input file type box to select the file and store its filename.

I've got this working to a degree - I can store the file name no problem.

What I'm wondering is if it is possible to instead of storing:

document.doc

to store

//localfileserver/path/to/file/document.doc

Is there a way to do this in PHP?
 
do you mean to store it in a NAS or something like that? actually I don't know, but (another point of view) why not mounting the shared folder and use it as local?

cheers.
 
I assume that you are storing the file path in a database.

When you save the path //localfileserver/path/to/file/document.doc into the database, what does it look like.

 
Yes, it's going into a MySQL database. I'm currently saving it using:

$_FILES['doc']['name']

so all that is stored is:

document.doc.

The reason I'm asking is that we want to link to documents on a number of different local fileservers to documents that don't move so it would be great to make this as simple as possible.
 
Just to confirm

On your form you type in:
//localfileserver/path/to/file/document.doc

And in your database it is saved as:
document.doc

1)Do you use something like the following for your file path on your form

<b>Path to file:</b>
<input type="file" size="60" name="find_file">

2)What is the properties of the field holding the path name in the MySQL Database

 
No, sorry, maybe I didn't explain that well.

On the html form, I've for an <input type="file"> so the user will select the file they want to link to.

The PHP script takes that variable in using $_FILES['doc']['name'] which only saves the actual filename: document.doc.

What I'm wondering is if there is a way to take in the network path as well as the filename?
 
The input element with type file is not meant to pass anything along but the filename. It is used for uploading the file to the server where it will be stored locally.
The fact that you are running this on a network where there might be accessibility to the file from the Web server does not change the behavior of the input element.
You might consider a PHP based file browser (which I don't recommend for security reasons) or have people paste the path into a text field.
 
how about this workaround. it uses the benefits of the file browser within the file type of the input element and then a tiny javascript moves the file name into a hidden field. the file does not upload because it is not within the form element that is submitted.

Code:
<?
if (isset($_POST['filename']))
{
	echo "received field data is $_POST[filename]";
	echo "<br /> remember to clean this before inserting into database<br /><br />";
}
?>
<head>
<script type="text/javascript">
function fillfield(val)
{
	document.getElementById("filename").value = val;
}
</script>
</head>
<body>
<input type="file" name="file" onblur="fillfield(this.value)" />
<form method="post" action=#>
	<input type="hidden" name="filename" id="filename" value="" /> 
	<input type="submit" name="submit" value="Submit" />
</form>
</body>
 
I am doing exactly what you want and I am using the input element as type file.

Can you print out the variable to a PHP page to see what the variable is holding.

Also your Mysql Statement, can you paste it in this thread

 
i think you can get it to work without javascript too.

by failing to specify any enctype for the form, the browser should fail to upload the file and just transfer the variable information.

the text within the input field cannot be got at through the $_FILES global variable. you will find it within the $_POST['filename'] variable.

you can also defeat the file upload mechanism by specifying that the form uses the GET method rather than POST.

of course, if you actually want the file uploaded then you need to include the enctype="multipart/form-data" and a max-file-size hidden input element before the file input element.

remember to clean the variable before uploading it to mysql:
Code:
$cleanedup = mysql_real_escape_string($_POST['filename']);
 
Yep, that's looking good. Thanks for all your help, it is very much appreciated!

Thanks

Steve
 
Hi, I can get these tricks to work in IE5+ but not in Mozilla. When I do the form post in mozilla i still get just the file name.ext in my db, when i do it in IE i get the full path and everything in my db. any help for a first time poster?

Cheers,
tony
 
oops sorry, that last post was directed at jpadie. jpadie, i omitted enctype, set method to get, etc, etc. and tested it a hundred times on mozilla, then by accident i tested on ie and it worked. my users use both, ie and mozilla, is there any browser preference in mozilla that will fix this? this is driving me nuts! I am trying to accomplish something similar to what sdalgleish described.

tusen,tusen takk!

tony
 
sorry, i'm not experienced on designing for mozilla. it sounds like one of the browsers is not standards compliant (i wonder which one...)

the javascript soln should work cross browser though.
 
yes, the script works fine. thank you all very much for a helpful post.

tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top