Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

input type=file

Posted on 2004-08-17
6
34,623 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
align Linkedin sign to the right page 5 55
How to combine and minify CSS and JS files 5 15
Asp in script 6 36
Set time on Session (ASP) 14 21
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…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

809 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