views:

71

answers:

2

I'm a javascript guy getting too deep into php (even though this question is not deep).

I am passing two different variables in the url from file to file. One goes across fine while the other does not.

I have 2 files. upload.php and uploadfiles.php.

The params help construct the destination to which the files are uploaded.

The two params are "memberId" and "fileType".

Here is where I pass the params to uploadfiles.php, this code is on upload.php.

Its in two places. One for a hidden input for a form and another passed as a var to a flash script.

On form:

<input name="uploadscript" id="uploadscript" type="hidden" value="/flashuploader/FileProcessingScripts/PHP/uploadfiles.php?memberId=<?php echo $_REQUEST["memberId"] ?>&fileType=<?php echo $_REQUEST["fileType"] ?>" />

In the js:

uploadUrl: '/flashuploader/FileProcessingScripts/PHP/uploadfiles.php?memberId=<?php echo $_REQUEST["memberId"] ?>&fileType=<?php echo $_REQUEST["fileType"] ?>'

I have tested on upload.php that $_REQUEST["fileType"] does indeed have the correct value.

And then I retrieve the params on uploadfiles.php like so:

$uploaddir=realpath(dirname(__FILE__) . '/../../../memberimages/') . '/'.$_REQUEST["memberId"].'/My_Files/'.$_REQUEST["fileType"].'/';

Param "memberId" works fine, but "fileType" is empty. I'm sure it has to do with the way that I am adding the params to the url with php on upload.php but I'm out of ideas.

Here is the html produced and returned by upload.php. You can see the values look correct on lines 44 and 80:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">

   function mysubmit(type)
   {
      if(document.getElementById("uploadscript").value=='')
      {
         window.alert('Enter upload processing script file name!');
         return false;
      }
      if(type=='flash')
      {        
         MultiPowUpload.uploadAll(document.getElementById("uploadscript").value); 
         document.getElementById("server_reply").value="";
      }
      else
      {
         var FormObj = document.getElementById("myform");
         FormObj.action = document.getElementById("uploadscript").value;
         return true;
      }
   }

   function MultiPowUpload_onComplete(type, index, serverResponse)
   {  
      var reply;
      reply = document.getElementById("server_reply");
      reply.value += "\nReply for file: " + MultiPowUpload.fileList()[index].name + "\r\n" + serverResponse + "\n";
   }
   var fileType = 'Video';
   function MultiPowUpload_onCompleteAbsolute(type, uploadedBytes)
   {
      if (fileType == 'Video'){
           parent.loadUserVideos();
      } else if (fileType == 'Images') {
           parent.loadUserImages();
      }
   }

  </script>

<div style="margin-top: -20px">
<input name="uploadscript" id="uploadscript" type="hidden" value="/flashuploader/FileProcessingScripts/PHP/uploadfiles.php?memberId=43&fileType=Video" />
<table width="380" cellpadding="0" cellspacing="0">
   <tr>
      <td style="position: relative;">
      <div id="MultiPowUpload_holder" style="margin-top: 20px">
      <table width="380" cellpadding="0" cellspacing="0">
         <tr>
            <td>
            <form id="myform" onSubmit="return mysubmit();"
               enctype="multipart/form-data" action="" method="POST">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
               <tr>
                  <td width="106"><span
                     style="font-family: Arial, Helvetica, sans-serif; font-size: 12px">Select
                  file:</span></td>
                  <td width="294"><input name="Filedata" type="file" /></td>
               </tr>
            </table>
            <br>
            <input type="submit" value="Upload File" /></form>
            </td>
         </tr>
      </table>
      </div>
      <!-- <img src="/images/ajax-loader.gif" style="position:absolute; top:40%; left:50%; margin-left:-110px;" /> -->
      <!-- SWFObject home page: http://code.google.com/p/swfobject/ --> <script
         type="text/javascript" src="/flashuploader/swfobject.js"></script> <script
         type="text/javascript">
         var params = {
            BGColor: "#FFFFFF"
         };
         var attributes = {
            id: "MultiPowUpload",
            name: "MultiPowUpload"
         };
         var flashvars = {
           uploadUrl: '/flashuploader/FileProcessingScripts/PHP/uploadfiles.php?memberId=43&fileType=Video',
           uploadButtonVisible: "Yes",
           useExternalInterface: "Yes",
           maxFileSize: "6024000",
           maxFileCount: "20",
           maxFileSizeTotal: "20480000",
           backgroundColor: "#FFFFFF",
           buttonTextColor: "#000000",
           buttonBackgroundColor: "#F1F1F1",
           buttonBottomBorderColor: "#E1E1E1",
           buttonTopBorderColor: "#E1E1E1",
           buttonDisabledBackgroundColor: "#FFFFFF",
           buttonDisabledBottomBorderColor: "#DDDDDD",
           buttonDisabledTopBorderColor: "#DDDDDD",
           buttonDisabledTextColor: "#DDDDDD", 
           buttonRollOverBottomBorderColor: "#666666",
           buttonRollOverTopBorderColor: "#666666",
           buttonDownBottomBorderColor: "#000000",
           buttonDownTopBorderColor: "#000000",
           buttonDownBottomBackgroundColor: "#FFFFFF",
           buttonDownTopBackgroundColor: "#FFFFFF",
           listTextSelectedColor: "#000000",
           listTextRollOverColor: "#333333",
           listRollOverColor: "#DDDDDD",
           listDownColor: "#EEEEEE",
           listSelectedUpColor: "#EEEEEE",
           listSelectedRollOverColor: "#D2D2D2",
           listUnuploadedColor: "#777777",
           listUploadedColor: "#FFFFFF",
           progressBarLeftColor: "#BBBBBB",
           progressBarRightColor: "#AAAAAA",
           progressBarLeftBorderColor: "#E1E1E1",
           progressBarRightBorderColor: "#E1E1E1",
           textColor: "#FFFFFF"
         };
         swfobject.embedSWF("/flashuploader/ElementITMultiPowUpload2.1.swf", "MultiPowUpload_holder", "380", "270", "9.0.0", "/flashuploader/expressInstall.swf", flashvars, params, attributes);

     </script></td>
   </tr>
</table>
</div>
</body>

Thanks for the help!

A: 

Hello,

I think so there is a VERY basic error in your code (uploadfile.php) ... you are trying to retrieve from the $_REQUEST wrong parameters..

From the HTML you are passing the hidden filed as "uploadscript" and you are trying to get $_REQUEST["fileType"] & $_REQUEST["memberId"] which dont exit.. (i dont know HOW you are getting the memberID unless it exists in the POST in some way or the other..

$uploaddir=realpath(dirname(__FILE__) . '/../../../memberimages/') . '/'.$_REQUEST["memberId"].'/My_Files/'.$_REQUEST["fileType"].'/';

Either,

  1. (PREFERED) send them as seperate parameters as you want them in uploadfile.php OR
  2. Recieve the $_REQUEST['uploadscript'] then explode and work on it ... (noob way)

ALSO, how is it that your HIDDEN Field is outside the FORM tag !!

<input name="uploadscript" id="uploadscript" type="hidden" value="/flashuploader/FileProcessingScripts/PHP/uploadfiles.php?memberId=43&fileType=Video" />

Hope that was helpful.

Accilies
@Accilies: 1. The hidden field is referenced by its id by a js onsubmit, doesn't need to be inside but I might as well move it. In the situation I am currently testing I don't use the form, I use the flash. The form is a backup for non-flash users. 2. When I load upload.php these params are passed to it in its url, I then add them to the url for uploadfiles.php which is called when the user submits the form with flash.
Dale
@Dale: OK. Does it actually post for non flash users? Your JS function submit requires one parameter which you are not passing from the form onsubmit function. Let me know if this is a typo when posting the quest so we can think differently... thanks
Accilies
Yes, it works using the normal form, but it has the same prob as the java form. Anyway, the accepted solution solved the problem.
Dale
A: 

I solved this by making the URL into just one parameter. I pass it along (after verifying that it is only strings and acceptable data) as one param to uploadfiles.php. For some reason the php didn't like more than one param.

Dale