Jump to content
  • Advertisement
Sign in to follow this  

[web] PHP HTML(file field)???

This topic is 4235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm using the html
 <input type="file" size="64" name="file" />
to be able to browse for a file, let's say I've picked a file with the path C:\webroot\image\test.jpg, is there any fast and easy way to be able to get rid of the C:\webroot\ and only be left with the image\test.jpg and passing it along with POST or GET. Or is the any other smart way to solve it. // The Asker.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure what you're tring to do...

The purpose of the file input is to upload a client file to the server. You don't upload the file path, but the file itself. If you truncate off the C:\webroot part then the user's machine won't know which file to attach in it's POST/GET. The server can't access the user's file system so truncating the path doesn't buy you anything.

-me

Share this post


Link to post
Share on other sites
Typically what happens here is that you:

1) Accept the file regardless of type and the form uploads it to a temporary directory on the server.
2) You validate the file type and content.
3) You then move it to where you want to store it on the server and delete the temporary one.

Dave

Share this post


Link to post
Share on other sites
Okey Sorry I wasn't clear enough, I'm trying to build a "input page" for a MySQL database, an I want to be able to just browse for a file (that will be saved and loaded on/from the server later on), input a little text about the image and some other stuff and then save all the info into the database, to later use that information to generate a dynamic webpage, and for that I would want just the image/xxx.jpg part of the file field.

and just use something like this to show the image:
 echo '<img name="" src="'.$Image_Path.'" width="50%" height="50%" alt="" />';


I'm sure there is a 1000 other (better) ways to do it, but I would like to do it like this, IF it is possible.

Thanks.

Share this post


Link to post
Share on other sites
So you don't want to actually upload the file? If you just want the path information you might be able to get it via javascript. If you do want to upload a file look into the php documentation: Chapter 38. Handling file uploads.

Edit: I see that you don't want to upload yet. In that case try this.

<script language="JavaScript"><!--
function extract(what) {
if (what.indexOf('/') > -1)
answer = what.substring(what.lastIndexOf('/')+1,what.length);
else
answer = what.substring(what.lastIndexOf('\\')+1,what.length);
alert(answer);
}
//--></script>

<form name="myform">
<input type="file" name="myfile">
<input type="button" value="Test" onClick="extract(this.form.myfile.value)">
</form>



Modifying that should be able to easily get the information you need.

Share this post


Link to post
Share on other sites
Yeah that's right I just want the path, and where holding my thumbs that there where some way to solve this using just HTML and PHP, I only been looking into the wonderful world of web programming for about 2 weeks, And hope to be able to stay away from Java for a couple more weeks :)

Share this post


Link to post
Share on other sites
By the way thanks tstrimp

That piece of code workt perfect.

yeah yeah and thanks to the rest of you guys, and perhaps gals ;) you'r all the best.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!