Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload Images...

Status
Not open for further replies.

dodgyone

Technical User
Joined
Jan 26, 2001
Messages
431
Location
GB
I'm creating an image upload facility but I'm having troubles getting the file variables on the upload page.

I know that enctype=&quot;multipart/form-data&quot; has to be entered into the form to accept the data uploaded but every document I have read suggests to put it in the <form> tag. This doesn't work when I try it but it does work when I place it in the <input name=&quot;userfile&quot; type=&quot;file&quot;> tag (i.e. <input name=&quot;userfile&quot; type=&quot;file&quot; enctype=&quot;multipart/form-data&quot;>).

I cannot use $userfile_name, $userfile_size etc etc to get the details on the upload process page. They won't pass through. Do I have to det up the apache web server differently. I don't have contact to the server side so I have to tell the guys what I want changed.

Thanks...
 
Have you tried using the [tt]$_FILES['userfile'][/tt] array instead? //Daniel
 
Yes I have used $_FILES['userfile']['name'] but still no joy.

I'm stuck ;o(

Thanks for trying to help...
 
Still no joy with file uploads. The php.ini file is all set up for file uploads. Is there anything else I can try?

[1]
I've entered the following into the form:
<input name=&quot;userfile&quot; type=&quot;file&quot; ENCTYPE=&quot;multipart/form-data&quot;>

I tried entering ENCTYPE into the <form> tag but it fails.

[2]
I've tried the following php upload codes in the resulting page but nothing is displayed:
echo $_FILES['userfile']['name'];
echo $HTTP_POST_FILES['userfile']['name'];
echo $userfile_name;

Other than that I have no idea. Does anyone have any suggestions...
 
It's working but something I didn't realise occurred.

I posted the form field to a new page and it didn't work but if I posted using php_self to post back to the same page then it would take the value.

Is this a usual occurrance in php?
 
I would assume so, I am not using php_self, considering I have multi-form submission processes included in the same php file, and the $filename_name extension does not work. I made up a code to bypass that. I don't really need the _type and _size extensions, so it doesn't bother me using this. So if you don't need to use those extensions either, feel free to use up this code:

$filenamearray = explode(&quot;\\&quot;, $filename);
$filenamearraysize = count($filenamearray);
$counter=1;
while($counter<$filenamearraysize) {
array_shift($filenamearray);
$counter = $counter+1;
}
echo $filenamearray[0];

Hope someone finds this useful :D
 
File uploads require two things in the form tag, one of which you seem to be missing in your example:

<form action=&quot;yourscript.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

Input tags do not support the &quot;enctype&quot; attribute.

The following works for me:

[test_upload.html]:
Code:
<html><body>
<form method=&quot;POST&quot; action=&quot;test_upload.php&quot; enctype=&quot;multipart/form-data&quot;>
<input type=file name=upfile>
<input type=submit>
</form></body></html>

[test_upload.php]
Code:
<?php
print '<pre>';
print_r ($_FILES);
print '</pre>';
?>

When I select the file &quot;DSCN0238.JPG&quot; in the HTML page and hit submit, I get the following return:
Code:
Array
(
    [upfile] => Array
        (
            [name] => DSCN0238.JPG
            [type] => image/pjpeg
            [tmp_name] => /tmp/phpxEjCdW
            [error] => 0
            [size] => 354499
        )

)


Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top