Link to home
Start Free TrialLog in
Avatar of rqs
rqs

asked on

PHP upload script won't upload. Problem with IIS config?

I have a script for uploading picture files to a MySQL table, running on an IIS 6.0 with support for PHP.
I think there is no problem with the script. The query performs the insert,
but the fields that will contain the picture file blob data, file size and type don't
contain anything coz $_FILES array simply doesn't contain the data.

In fact, after turning on error_reporting, it warns at the line $_FILES['emppic']...
that emppic is an unrecognized index. I double checked the form tags, the file input type
is named emppic, no typo errors. the needed enctype="multipart/form-data" is also there.

I checked php.ini, file_uploads is turned on. the upload directory points to a location
that IIS could write to (for testing, I pointed it to the location where the session files
are save, coz I'm sure IIS could write to that directory, my sessions work). upload size is set to 2M.

I've run out of ideas. I'm quite inclined that this is an IIS config problem. Maybe it blocks posting or
uploading of files. Or maybe there is a DLL that I need to enable or install first (I read an article
that requires a DLL to be configured with IIS or ASP pages). Any solutions?





Avatar of rqs
rqs

ASKER

No response yet =(

If I do an echo $emppic, the browser displays the path to the file on
the local machine of the user who wishes to make the upload...
so the form data received by the server is not entirely empty, but terribly incomplete
Avatar of rqs

ASKER

I read somewhere that the variable $emppic should rather contain the
file name and fullpath to where IIS saved the uploaded file... but here I am
getting the full path name on the machine of the user uploading the file
Avatar of skullnobrains
hello, follows part of an an old script that has the advantage to display (in an ugly manner) the infos on the file transfer. you'll find the way to use the file afterwards.

-----------
//switch($operation):
//       case"ajouter"://ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-ajouter-
          if($exe_file == ""){echo"pas de fichier spécifié => ajout impossible";break;}
          foreach ($_FILES['exe_file'] as $var => $val)$$var=$val;//print_r($_FILES);
          echo "<table cellpadding=0><tr><td rowspan=4>données de reception</td><TD width=25 rowspan=4>
                <td><b>nom : </b><td>".$_FILES['exe_file']['name']."<tr><td><b>type :</b><td>$type<tr>
                <td><b>taille :</b><td>$size octets";
          if($exe_ajout>100)$type="gifpng"; else $type="images";
              if($size>$MAXUPL[$type]){echo"<br>la taille maximale autorisée sur ce site est ".$MAXUPL['images'];$err=1;}
          echo"<tr><td><b>statut :</b><td colspan=2>";
          switch($error):
              case"0":echo"telechargement réalisé avec succès</table>";break;
              case"1":echo"fichier trop volumineux pour être uploadé sur ce serveur !<br>
                    taille du fichier : $size</table>";$err=1;break;
              case"2":echo"la taille maximale des fichiers pouvant être envoyés à votre
                    navigateur n'est pas suffisante pour uploader ce fichier";break;
              case"3":echo"le fichier n'a été que partiellement transféré
                    <a href=\"#\" onClick =\"document.choix.submit();\">réessayer</a><tr><td></table>";$err=1;break;
              case"4":echo"pas de fichier correspondant au chemin spécifié</table>";$err=1;break;
              default:echo"aucune erreur n'a été retournée mais le fichier n'a pu être transféré
                    <a href=\"#\" onClick =\"document.choix.submit();\">réessayer</a><tr><td></table>";$err=1;break;
          endswitch;
          if($err){echo"<font color=red>echec lors du transfert de fichier !!!</font>";break;}

-------------------------

to use the result :

$HTTP_POST_FILES['myfile']['tmp_name'] -- Contains the full path and filename of the uploaded file as stored on the server.

$HTTP_POST_FILES['myfile']['name'] -- Contains the full path and filename of the uploaded file as stored on the client.

$HTTP_POST_FILES['myfile']['size'] -- Contains the size of the file in bytes

$HTTP_POST_FILES['myfile']['type'] -- Contains the MIME type information associated with the file (if any)

myfile is the name of the input in the form not the filename

the 5th variable is $error (see my old and ugly code for a way to use it)

more information on http://www.zend.com/zend/spotlight/uploading.php
or anyother online php manual : nexen, phpnukes, .... dozens available

let me suggest you to read that page in it's full extent before you try or post anything more, and in such cases you try &alt? printr($FILES);?> just in case in the first place.
case"0":echo"upload OK</table>";break;
              case"1":echo"file too big<br>
                    file size : $size</table>";$err=1;break;
              case"2":echo"navigator upload limit exceeded or protocol error";break;
              case"3":echo"the file has only been partly transferred <a href=\"#\" onClick =\"document.choix.submit();\">try again</a><tr><td></table>";$err=1;break;
              case"4":echo"file not found => check local client path</table>";$err=1;break;
              default:echo"unknown error"; break;

... just the english version of the sole usefull part of the previous script.
Avatar of rqs

ASKER

I'm more convinced it's not with the scripts that I am having problems with but with IIS 6.0
configuration and/or PHP configuration.
Whether I use any of these variations on coding:
    $_FILES['emppic']['tmp_name'], etc.
    $HTTP_POST_FILES['emppic']['tmp_name'], etc.
    $emppic_name, $emppic_type,  etc...
no reference to where the uploaded file was temporarily saved could be fetched. echoing the variables simply yields an empty string. If I check the upload directory I specified in php.ini, no new files are saved or uploaded at all.
That's why I guess the $_FILES or $HTTP_POST_FILES don't contain any data. HTTP POST file uploading
somehow doesn't succeed.

I followed the config instructions for enabling file uploading in PHP ini (3 variables have to be set, one of which is
file_uploads = On) With IIS 6.0 , I made sure the upload directory is writable by IIS. After all that, file uploading still doesn't work. =(

quote from myself
-- myfile is the name of the input in the form not the filename --
did u really check this out ?

unless this is enough to make it work, can't u send over <? print_r($_FILES);?>

if you have a browser problem, you should stiil get the $_FILE[inputname][error]

as far as i know, (but there certainly is more to that) the way to prevent uploading in iexplore is either turn the maxsizeupload to a ridiculously low value or use a plugin wich usually will give an error message. (in the browser)

you might also get a firewall issue but then, there again should be an error variable set.

if $_FILE is really empty, send over the adress of you site and i'll try with my iexplore6 which i know will let me upload files allright.
Avatar of rqs

ASKER

Here's my HTML:
<form enctype=\"multipart/form-data\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\" >
<input type=\"file\" name=\"employeepic\" size=\"40\">
<input type=\"submit\" name=\"Submit\" value=\"Submit\">                                            
</form>

And here the snippet where I try to print debug info:
echo "Remote File name: a) $employeepic b) {$_FILES['employeepic']['name']} c) {$HTTP_POST_FILES['employeepic']['name']}<br>";
echo "Server File name: a) $employeepic_tmp_name b) {$_FILES['employeepic']['tmp_name']} c) {$HTTP_POST_FILES['employeepic']['tmp_name']}<br>";
echo "Errors: {$_FILE['employeepic']['error']}";
echo "FILES superglobal: ";
print_r($_FILES);

This is the html output:
Remote File name: a) C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\winter.jpg b) c)
Server File name: a) b) c)
Errors: exasperated: Array ( )

Only $employeepic contains data. I'm rereading the site you gave me, just in case I did miss something.
Am trying it now on two setups: a PHPDEV (APACHE) on a WinXP desktop and my IIS6.0 win2k3 server.
So far, I'm encountering the same results.

Here's the fragment of the PHP.ini's, which the manuals I read say are the only setting I had to reconfig
;***********************
;Machine running APACHE. PHPDEV here is installed as a service and logs on as my
;machine account with write permissions to the c:\windows\temp folder
;*********************
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\windows\temp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M


;***********************
;Machine running IIS6.0. I'm sure IIS6.0 has write permissions to the c:\inetpub\temp folder
;because my session files can get saved here, otherwise, PHP sessions wouldn't work
;*********************
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\Inetpub\temp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

My machines are behind a firewall and only accessible within our LAN.

Regarding my browser, I can upload attachment files to yahoo mail.
So I guess it's not setup to prevent file uploads, right?
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks both.

this question would definitely have closed better on an answer.
if you are still around rqs, it would be great to let us know what the problem was.
Avatar of rqs

ASKER

As for the problem, I wasn't  able to fix it now but just
guessed, based also on links you've given and others that I came across with,  that
it's really a problem between PHP and IIS 6.
Momentarily, I proceeded with other parts of my project.
But I'm also guessing, hoping maybe if I upgraded my php binaries, the problem
would go away. Will try that the soonest possible and I'll probably post the results here.

Thanks