This is a program to allow an upload of a pdf file. The pdf file will be checked to see if it is a pdf, checked to make sure the file doesn’t exist. Then if all is well it is added to an array and a html document is generated based on all of the pdf files located on the server. I can’t figure out why this dosen’t work. When I trim the program down to the basics where a pdf can be uploaded, no checks are made, and the file is rewritten with php code without using an array but rather previous_contents of the file and then just adding the new file to the html document, the program works. When I add the extra features it wont work. Wont work means when I upload the file the result is a blank white page.
This code is where the user uploads the file(this is just a snippit, all the proper html tags do exist on the page:
[code]
Please choose a file:
Make sure your file name is #.pdf. (Example: Bugle #71 should be named 71.pdf) After uploading you will be logged out [/code]
Thank you.
This is upload.php this is where the problem is
[code]
<?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']); //upload is passed from html submit forum $filename=$_FILES['uploaded']['name']; $checkpdf=substr($filename,-3);//string with file extension $counter = 0; $arr = array();    if($checkpdf !== "pdf")
    {
        echo ($checkpdf. " This is checkpdf variable n");
        echo ($filename." is not a PDF, please upload a pdf file. n");
        return;
    }
    
    if($dir = opendir('./pdf'))
       {
        while (false !== ($file = readdir($dir))) {
                if ($file != "." && $file != "..") {
                        array_push($arr,substr($file,0,-4));
                        echo(array_values($arr));
                    }
            }
        closedir($dir);
        }
    if (array_search(substr($filename,0,-4),$arr))
     {
        echo ($filename." already exists. Please try again.");
        return;
     }
    
    else
    {
        array_push($filename,$arr);
        rsort($arr);
    
    }
    
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) 
        {
    
        exec('mv ./upload/* ./pdf/');
        $jpeg = ("/srv/www/htdocs/nuffle/bugle/pdf/thumbs/$myname.jpg"); 
        exec("convert -resize 200x258 ".$pdf."[0] ".$jpeg);//create thumbnail from pdf
        exec('cp /home/nuffle/static/html/league.html /home/nuffle/static/html/league_old.txt'); //back up, before overwriting
    
        $handle=fopen("/home/nuffle/static/html/league.html","w");
    
        foreach($arr as $myname)
            {
                mystring='<td><p align="center"><a href="http://76.109.201.110/nuffle/bugle/pdf/' . $myname .'.pdf" target="_blank"><img src="http://76.109.201.110/nuffle/bugle/pdf/thumbs/' . $myname .'.jpg" width="200" height="258" alt="bugle' . $myname .'" /></p><h3 align="center">Bugle #' . $myname . ' </h3></a>';
                $counter += 1;
                if($counter == 4)
                    { 
                        $mystring .="<br />";
                        $counter = 0;
                    }	
                fwrite($handle,$mystring);
            
            }
    
        fclose($handle);
    
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded <br />";
        echo ' <a href="#" onClick="history.go(-1)"></a><input type=button value="Back To the Upload Page" onClick="history.go(-1)">';
            
      //exec(`/home/nuffle/restart_once.sh`); //refreshes python webserver
    
    }
    
    //else { echo "Sorry, there was a problem uploading your file.n Please go back and try again. If the problem persists contact the webmaster n";
    //echo ' <a href="#" onClick="history.go(-1)"></a><input type=button value="Back" onClick="history.go(-1)">';
    //}
    
    ?>
    
</body>
