upload form and php question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dima1236
Forum Newbie
Posts: 2
Joined: Tue Apr 01, 2008 1:09 pm

upload form and php question

Post 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";
        
?>
 
Last edited by dima1236 on Tue Apr 01, 2008 1:44 pm, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: upload form and php question

Post by s.dot »

You should be referencing $_FILES['userfile'] in encode.php, currently you are using $_FILES['file']
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dima1236
Forum Newbie
Posts: 2
Joined: Tue Apr 01, 2008 1:09 pm

Re: upload form and php question

Post 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:
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: upload form and php question

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: upload form and php question

Post 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
Post Reply