Page 1 of 1

upload form and php question

Posted: Tue Apr 01, 2008 1:13 pm
by dima1236
hello guys something is driving me crazy , i got Html file that contains simple file upload
and php file that should get the path of the file and read only some of the file , then run com file and store it on the server
but the program begins when i CANT extract path or anything from the html file
please hel me

upload.html:

Code: Select all

 
 
<form action="encode.php" method="post" enctype="multipart/form-data">
   <p>
      <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
      <button>Upload File</button>
   <p>
</form>
 
encode.php

Code: Select all

 
 
<?php
//this 4 lines returns nothing :(! and all i need is to have $path
 echo "Upload: " . $_FILES["userfile"]["name"] . "<br />";
  echo "Type: " . $_FILES["userfile"]["type"] . "<br />";
  echo "Size: " . ($_FILES["userfile"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["userfile"]["tmp_name"];
 
 
    switch (filetype($path)) {
    case "dir":
            echo "this function is not yet implemted";
            break;
    case "file":
            {
            $mp3File = fopen($path,"r");
            $SampleSize=filesize($path) / 4;
            fseek($mp3File, 1048576);  //skip 1mb
            $data = fread($mp3File, $SampleSize);
            $SampleName="Sample_" .basename($path);
            touch($SampleName);
            chmod($SampleName,0666);
            $mp3Sample = fopen($SampleName,"r+");
            fwrite($mp3Sample,$data);
            
                
            fclose($mp3Sample);
            fclose($mp3File);
    
                $runLame = "c:\\wamp\\www\\lame.exe --abr 64 -f c:\wamp\www\Sample_temp.mp3";
                $WshShell = new COM("WScript.Shell");
 
                 $output = $WshShell->Exec($runLame)->StdOut->ReadAll;
                if (strpbrk($output,"done")) { 
                  echo $SampleName." Seccessfully Encoded" ;
                } else {
                 echo "Faild";
                }
            
        }
     break; 
    
}
 
 
 
 
//$path="c:\\wamp\www\\temp.mp3";
        
?>
 

Re: upload form and php question

Posted: Tue Apr 01, 2008 1:28 pm
by s.dot
You should be referencing $_FILES['userfile'] in encode.php, currently you are using $_FILES['file']

Re: upload form and php question

Posted: Tue Apr 01, 2008 1:43 pm
by dima1236
scottayy wrote:You should be referencing $_FILES['userfile'] in encode.php, currently you are using $_FILES['file']
fixed that
and still all i get by running it :

Code: Select all

Upload:
Type:
Size: 0 Kb
Stored in:

Re: upload form and php question

Posted: Tue Apr 01, 2008 5:02 pm
by flying_circus
I cant remember why, but I remember having to make a hidden form field like this:

Code: Select all

 
<form action="encode.php" method="post" enctype="multipart/form-data">
   <p>
      <input type="hidden" name="MAX_FILE_SIZE" value="2097152">
      <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
      <button>Upload File</button>
   <p>
</form>
 
Other than that, your code looks pretty similar to mine.

Re: upload form and php question

Posted: Tue Apr 01, 2008 5:21 pm
by aceconcepts
Take a look at: http://uk3.php.net/features.file-upload

Also this will help with the MAX_FILE_SIZE hidden field: http://uk3.php.net/manual/en/features.f ... errors.php