Solved

input type=file

Posted on 2004-08-17
6
34,626 Views
Last Modified: 2011-08-18
I am using PSP (PlSql Server Pages) for web development.
I want to assign value for <input type=file  value=.....> Where the value is taken from the database.
I came to know its not possible.
What alternative should I go about.
I have an Upload CGI script which uses this file name to upload file to my file server.
The main problem I have is, I cannot change my CGI as I am not aware of it. (Its a downloaded script) , i.e., by changing input type=text my CGI is not responding right way...

Early help solicited.
Thanks in advance
0
Comment
Question by:sgayatri
6 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11827846
I'm afraid it is impossible to set a default value for file input. If you could, it would be a huge security risk because you can just upload any file on the user's computer on to yours without their notice even (with Javascript submit() and stuff).

The best (if not only) choice that I see is for you to make the user choose the file all over again. It's a bit forced, but the easiest and only choice I see currently.
0
 
LVL 2

Expert Comment

by:phpisthefuture
ID: 11828043
I am pretty sure there should be a way to do that with CGI. Here's how you do that with PHP:
<input type="file" value="<?php echo $FileName ?>">

Here's two solutions which I just thought about:
1)
write a sql to pull file names from the database field you want and assign them to $FileName variable.
Just to give you an idea how you can work the database part;
Add an extra field after "FileName" such as "Assigned" in your database
Pull the first filename field value from the database, then update let's say "YES" to the Assigned field of that filename.
Each time you want to pull the filename from the database check Assigned field with value "NO", create a basic loop and always call next filename with assigned value "NO".
Ex:
First input will check the database and pull first filename filed called "File1", and it will update the assigned value to "YES".
Second check will look for the first filename field with assigned value "NO", will find "File2" and will update assign value to "YES" and so on.
So when you check the uploaded files by users, the names will be:
File1
File2
File3
File4
......
I think this was what you are trying to do.

2)
If you want to assign specific names, such as BMW, Elephant, Computer, Resume etc. to your files.
Exactly same idea with solution 1. You can add an extra field, and start with row1 and so on, always update assigned value to "YES" if somebody clicks submit to upload a new file, then next user will be getting the next name from the database.

I hope this will give you a general idea about how to solve this problem with a server side language.
Good luck and let me know if you have any further questions.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 11829588
>>1)
write a sql to pull file names from the database field you want and assign them to $FileName variable

wont work, any value assigned to an input type=file object is ignored by the object, text key entered or enterred by cut and paste is ignored, the file object is very secure and can only be interacted with in a very inute way and only on certain browsers, IE, and all you can do is check that there is a value

there are private member settings in the object that can only be manipulated by the object and these determine 1 was the file browsed yes/no if yes then ok if no then you will never upload this file
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:sgayatri
ID: 11838300
I agree with what Zyloch has written.
My main problem is I do not want the user to go to any folder and upload files by fancy. Can I atleast limit the browse button of FILE box to a specific folder in the client. That would atleast makes me feel more secure that I am limiting the user from choosing dirty files.
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 250 total points
ID: 11850415
Don't know much about that, but you can limit the file types the user can upload and the max file size.

Have this in your form for max file size in bytes (I believe) (have it above your input type=file for safety)

<input type="hidden" name="MAX_FILE_SIZE" value="1024000">

(This should be 5meg)


As for file type, in the input type=file, you can have ACCEPT, check here (http://www.blooberry.com/indexdot/html/tagpages/i/inputfile.htm) for specifications. An example:

<input type="file" accept="*.gif,*.jpg">


This could be ignored, so on the server side, you can test the file type using PHP filetype()
0
 
LVL 3

Author Comment

by:sgayatri
ID: 11857814
The check of max file size and file type is already embedded in my CGI. Anyway, thanks for the suggestions and the URL given by Zyloch is quite informative.
Thanks Zyloch.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML <font style="color:red"> 9 51
CSS DIV Height in Percent 1 25
Compute age Html 2 23
Validating number not work with decimal 4 23
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question