Computing.Net > Forums > Web Development > html input type=file and php

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

html input type=file and php

Reply to Message Icon

Name: eaw8806
Date: March 28, 2004 at 09:16:58 Pacific
OS: win 98
CPU/Ram: pentiumII/128MB
Comment:

recently i've been working on this blogging application, and i wanted a way to allow users to upload pictures to the server, when they are logged in, to a folder. i have 2 problems. i know i should use the input type=file tag, and i think in the form tag, enctype=multipart/form-data method=post is what i need to do, but im not quite clear on how to get the file contents, from the server end in php. if i dont define the enctype, and say input type=file name=fileimg , then in the php, $HTTP_POST_VARS["fileimg"]; will be the path of the file the user selects, but when i do the enctype, that var is blank. is there a different var, or array that it is being written to? im stuck as to where to go on this.

the second problem i have, is creating files. using filezilla, i created a folder, with the properties of everything (777), and used fopen(); fputs() fclose();, but the file is not created. i think this may have to do with the file permissions, but as i said, i set the folder to 777, so i do not think this should be an issue.

any help on either of these problems is appriciated. thanks,
eaw8806



Sponsored Link
Ads by Google

Response Number 1
Name: anonproxy
Date: March 28, 2004 at 10:03:55 Pacific
Reply:

You are correct to use Input="file" and Enctype="multipart/form-data". You seem to understand the file is uploaded via a POST transaction. Therefore, it automatically becomes an element, named by the HTML form's value="" attribute, in the superglobal $_FILES (PHP 4.1.x and above). Consider this superglobal like an object which inherits several methods such as tmp_name, name, size, and type.

The only user which needs 777 permissions in the folder is the apache server (remember the server is the proxy for all user access). See if 711, 755, or 644 works (we are only speaking of the applicable directory).

Good documentation at Zend.com and PHP.net. A permissions reference is here.



0

Response Number 2
Name: eaw8806
Date: March 28, 2004 at 15:03:06 Pacific
Reply:

i think i understand what $_FILES is...its kinda like $_POST and $_SESSION....so do i use $_FILES["imgfile"] like its an array? where imgfile is the name of the form? or the input? hmm...well i'll just experiment with it.

i'll try those other permision settings too...thanks for your help on both topics anonproxy.

-eaw8806


0

Response Number 3
Name: eaw8806
Date: March 28, 2004 at 15:28:09 Pacific
Reply:

yup, so i figured it out, i did
$imgfile = $_FILES["imgfile"];
foreach($imgfile as $key=>$value){
echo "imgfile[$key] = $value

";
}
and got the name, type, tmp_name, error and size. so i decided to experiment with tmp_name, and i opened it, and the file i uploaded was there! now i did run into another problem...i think the server is linix, so does that mean files end with a \n? because when i echo what i read from the file, all i get is the first line. i think theres a way to get around this, by specifing the length that is read. and since i have imgfile[size] i think it might work. thanks for your help again.

eaw8806.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: html input type=file and php

Uploading a file using php www.computing.net/answers/webdevel/uploading-a-file-using-php/2751.html

.htaccess and PHP www.computing.net/answers/webdevel/htaccess-and-php/286.html

how to display images in PHP www.computing.net/answers/webdevel/how-to-display-images-in-php-/2164.html