Confusing PHP problem

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
treyk4
Forum Newbie
Posts: 1
Joined: Sun Aug 24, 2008 7:44 pm

Confusing PHP problem

Post by treyk4 »

Hey all,
I've recently installed DevkitPPC (the toolchain for building wii programs), and have attempted to make a PHP script to:

1 - Upload a .zip file containing a makefile in the root of it, and a folder titled "source" containing, well, the source code.
2 - Make a temporary folder for the source to be unzipped to
3 - Unzip the source to the temporary folder
4 - Run make to compile the program.
5 - Give you a link to the .elf file

And it doesn't quite work.

I'm a python programmer that's in the process of learning C and C++, and I just use PHP on the side every now and then for the websites I make, soy my PHP might not be using very good practices.

Here's the source:

Code: Select all

<?php
//////////////////////////////////////////////
// Setup section
 
$filepath = 'files/';                // Location of uploaded files
$zippath  = 'zip/';                  // Location where each of the source's folders are placed
$pass     = 'thisisthepassword';  // Password
 
// No need to change anything after here.
//////////////////////////////////////////////
function check() {
  session_start();
  $session = $_SESSION['captcha'];
  $image = $_POST['image'];
  $image = md5($image);
 
  if ($session == $image){
    return 8;
  } else {
    return 9;
  }
}
function redirect($link) {
  //$pageaddr = 'Location: ' . $weblocation . 'return.html?link=' . $link;
  //header($pageaddr);
  echo $link;
}
function microtime_float() { // Not how it should function, this is just for testing.
    return 4000;
}
 
$pwd = $_POST['passwd'];
if ($pwd == $pass){
  if (check() == 8){
    $target_path = $filepath;
    $bname    = basename( $_FILES['uploadedfile']['name']);
    $target_path = $target_path . $bname;
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
      $temfoldername = microtime_float();
      echo $tempfoldername;
      echo "<br>";
      $mlast = system('mkdir ' . $tempfoldername, $retvalm);
      echo $retvalm;
      echo "<br>";
      system('cd ./' . $zippath . $tempfoldername, $retval);
      echo $retval;
      echo "<br>";
      $zlast = system('unzip ../../' . $target_path, $retvalz);
      echo $retvalz;
      echo "<br>";
      $makelast = system('make', $retvalmake);
      echo $retvalmake;
      echo "<br>";
      redirect($zippath . $tempfoldername . '/' . $tempfoldername . '.elf');
    } else {
      echo "There was an error uploading the file, please try again!";
    }
  } else {
    echo "Incorrect verification code.";
  }
} else {
  echo "Wrong password!";
}
 
?>
 
Here's the output from the program:

1
0
9
2
zip//.elf
Note that the first line's blank.


This one has been completely perplexing me. I've tried everything I know of, but to no avail.

Any help would be greatly appreciated!!!

Thanks,
treyk4
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

Re: Confusing PHP problem

Post by marcth »

If you can't find what's adding the white space, use the following code to solve your problem.

Code: Select all

ob_start();
//Insert your code here
$contents = trim(ob_get_clean());
 
print $contents;
Post Reply