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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with wamp server 1

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
I have this bit of code in the calling prog

Code:
<form enctype="multipart/form-data" action="uploader.php" method="POST">


and this bit in the called prog

Code:
die(basename($_FILES['uploadedfile']['name']));

returns nothing

Definatly not rocket science

works fine in the dev area and live area's but won't work at all on the wamp server

ideas gratefully received


Richard
 
What are you trying to do?

Die as it suggests will just end the script at at that point.

However you have not shown us the rest of your form. the $_FILES super global will only be populated if your form contains a "file" field that is submitted.

And Basename takes a full path. the name key from the $_FILES array is I believe just the filename with no path.

Does the WAMP server have a defined upload dir in its PHP.ini file?


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
instead of looking for the basename of a browser supplied field (the name) try instead to print_r the relevant $_FILES element. this will tell you whether everything is properly completed and what the error status is.
 
Hi

I put a die in there so that I could see the contents of the variable (which is empty)

The rest of the code was nicked off this site and works fine on an apache server. I am working away and have to use a data card that is running at 56K so it takes forever to test.

do I need to initialise the $_FILES variable somewhere & if so how

I have tried this at the top of the calling prog inside the php area

$_FILES['uploadedfile']['name'] = '' ;

Regards


Richard
 
the $_FILES is a superglobal variable it does not need to be initialized.

You could have echoed the variable:

echo $_FILES['...'][''];

Anyway what happens if you follow jpadie's suggestion and print_r the variable:

Code:
echo "<pre>";
print_r($_FILES);
echo "</pre>";



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Code:
Notice: Undefined index: uploadedfile in C:\foxsce\webaccounts\adm\uploader.php on line 13

It looks as if the variable is empty
 
Which means the upload is not going through. O.k again I ask does the WAMP server have a correctly defined upload dir in its php.ini file?

upload_tmp_dir.

Also try the complete $_FILES variable without any index:
echo "<pre>";
print_r($_FILES);
echo "</pre>";

Does it show anything?


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i think you should post your html form code too.
 
First keep in mind this all works on an apache server

Second will the fact that no upload dir be relevant as it doesn't even get the name of the file to uploader.php

I will sort out the directory in php.ini on my break later

Here is the html code

Code:
<?php
if(session_id() == "") {session_start(); } 

if ($_SESSION['login'] != 'Y')
	{die('Session not initialised -- please log in');}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	font-size: 18px;
}
.style6 {font-size: 14px; font-weight: bold; }
body {
	background-color: #99CC99;
}
.style10 {font-size: 12px}
-->
</style>
</head>

<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">


<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="20%"  border="3" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
      <td colspan="3"><div align="center"><span class="style1"><u>Importing SDL file </u></span></div></td>
    </tr>
    <tr>
      <td><span class="style6">File to upload</span></td>
      <td colspan="2"><input name="uploadedfile" type="file" id="uploadedfile" /></td>
    </tr>
    <tr valign="middle">
      <td colspan="3"><div align="center">
        <p class="style10">The Excel File needs to be saved as a </p>
        <p class="style10"> (tab delimited) txt file first </p>
      </div></td>
    </tr>
    <tr valign="middle">
      <td colspan="3"><div align="center">
        
          <input name="Upload" type="submit" id="Upload" value="Upload" />
        
      </div></td>
    </tr>
  </table>
</div>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
 
and what do you get if you change uploader.php to contain the following

Code:
echo "<pre>";
print_r($_FILES);
echo "</pre>";
exit();

obviously we're looking for the output once you have tried to upload something.

please also run this script and post the results

Code:
$array['file_uploads'] = ini_get('file_uploads');
$array['directory'] = ini_get ('upload_tmp_dir');
$array['maxsize'] = ini_get('upload_max_filesize');

echo "<pre>";
foreach ($array as $key=>$val){
 echo "$key \t $val";
}

if (!is_dir($array['directory']) && !empty($array['directory'])){
 echo "upload directory is incorrectly specified";
}

if (!is_writable($array['directory']) && !empty($array['directory'])){
 echo "upload directory is not writable;
}




 
Hi jpadie

The first bit has already been run the result is

Code:
Notice: Undefined index: uploadedfile in C:\foxsce\webaccounts\adm\uploader.php on line 13

Will do the rest shortly
 
sorry bertie - it cannot have been run. there is no conceivable way that you could get the error you have quoted from the code i have posted.
 
Sorry I had run something similar but not the same


the result is
Code:
Array
(
)

I had run

Code:
print_r ($_FILES['uploadedfile']['name']);
 
and what output do you get from the second script?
 
Thats the undefined index above.

I could put the info into a session variable, I am just curious that the wampserver won't pass the info.

It works perfect on my development site,
 
again - that is not a possible response. we know that each index is defined because they are hard-coded. I refer, of course, to the second script that i posted in my last major post.
 
Hi jpadie

Sorry I didn't have my brain in gear

Here is the result

file_uploads directory c:/wamp/tmpmaxsize 2M


 
so it looks as though file_uploads has been turned off, and the directory is pointing to some sub-directory of wamp called c:/wamp/tmp.

you need to edit the php.ini file to turn file_uploads on (it's possible that boolean true is not translating to a 1 in the output so it could be that this is not a problem).

i would also recommend upping the post_max_size and upload_max_filesize directives to a healthier number. whilst your uploads should still be populating the $_FILES error to some extent (the errors for example), it's possible that this is a cause.

next make sure that error_display and display_startup_errors are set to on and that error_reporting is set to E_ALL. that will help display any messages that are being suppressed. in the meantime you could look in the log files to see whether you are getting any errors.

lastly is it possible that you are using an absolute url in the html code and that this is pointing to your dev server and not the wamp version? although i see that the form action is a relative url, this could be being hijacked by a meta base declaration in the head tags.
 
jPadie

That was absolutly brilliant, it also solved the problem as to why phpmyadmin would not import more than 2M

Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top