Solved

input type=file

Posted on 2004-08-17
6
34,616 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now