Solved

input type=file

Posted on 2004-08-17
6
34,618 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Find out what you should include to make the best professional email signature for your organization.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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)

786 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