Page 1 of 1

PHP Upload Issues

Posted: Mon Jul 20, 2009 4:57 pm
by beanboy3001
I downloaded this php code and modified it. It is supposed to work with a swf file upload and save it to my site. Can anyone help me figure out why the uploaded says that the file upload is complete and shows no errors but when I check the folder there is nothing in it.
I love learning php but am fairly new at it. But I'm now reaching the end of my rope on this one...
Any help is appreciated :)

Code: Select all

<?php
 
 
    
    #   Setup SWFUpload Email Notify
    #   --------------- 
    
        $upload_email_reporting = true ;    // true or false (false turns email reporting off)
    
        $upload_notify_email = 'jonathan@bdglr.com' ;   
        
        $upload_directory = '' ; // leave blank for default
        
        
        
        
    #   PHP Email Configuration Test
    #   --------------- 
        # Set to "true" to test if your server's PHP mail() function configuration works, by attempting to upload one file.
        # A simple email will be sent per upload attempt, letting you know PHP's mail() funciton is working.
        $test_php_mail_config = false ; // true or false
        
 
 
 
 
 
 
 
    
 
    #   CREATE DEFAULT UPLOAD DIRECTY LOCATION
    #   --------------- 
        If ( !$upload_directory ) {
            $upload_directory = 'uploads' ; 
            $parent_dir = array_pop(explode(DIRECTORY_SEPARATOR, dirname(__FILE__)));
            $upload_directory = substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen($parent_dir) ) . $upload_directory ; 
        }
 
        
 
    #   --------------- 
    #   EMAIL TESTS
        If ( !$upload_notify_email ) {
            $upload_email_reporting = true ;
        }
        # Sends one email per SWFUpload attempt. 
        if ( $test_php_mail_config == false ) {
            send_mail("SWFUpload Email Test: SUCCESS!",'Be sure to set $test_php_mail_config back to false so that SWFUpload Email Notify reporting is turned on.'); 
            $upload_email_reporting = false ;
        }
    
    
    #   --------------- 
    #   TEST UPLOAD DIRECTORY
 
        If ( !file_exists($upload_directory) ) {    
            $msg = "The assigned SWFUpload directory, \"$upload_directory\" does not exist."; 
            send_mail("SWFUpload Directory Not Found: $upload_directory",$msg);
            $upload_email_reporting = false ;
        }
        if ( $upload_email_reporting == true ) {
            $uploadfile = $upload_directory. DIRECTORY_SEPARATOR . basename($_FILES['Filedata']['name']);   
            if ( !is_writable($upload_directory) ) {
                $msg = "The directory, \"$upload_directory\" is not writable by PHP. Permissions must be changed to upload files."; 
                send_mail("SWFUpload Directory Unwritable: $upload_directory",$msg);
                $upload_directory_writable = false ;
            } else {
                $upload_directory_writable = true ;
            }
        }
    
 
    // Work-around for setting up a session because Flash Player doesn't send the cookies
    if (isset($_POST["PHPSESSID"])) {
        session_id($_POST["PHPSESSID"]);
    }
    session_start();
 
 
 
    if ( !isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
        
        #   --------------- 
        #   UPLOAD FAILURE REPORT
            if ( $upload_email_reporting == true ) {
                switch ($_FILES['Filedata']["error"]) { 
                    case 1: $error_msg = 'File exceeded maximum server upload size of '.ini_get('2GB').'.'; break;
                    case 2: $error_msg = 'File exceeded maximum file size.'; break;
                    case 3: $error_msg = 'File only partially uploaded.'; break;
                    case 4: $error_msg = 'No file uploaded.'; break; 
                }
                send_mail("SWFUpload Failure: ".$_FILES["Filedata"]["name"],'PHP Error: '.$error_msg."\n\n".'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
            }
            
    
        echo "There was a problem with the upload";
        exit(0);
 
    } else {
    
 
        #   --------------- 
        #   COPY UPLOAD SUCCESS/FAILURE REPORT
            if ( $upload_email_reporting == true AND $upload_directory_writable == true ) {
                if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
                 send_mail("SWFUpload File Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
                }else{
                 send_mail("SWFUpload File Not Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
                }
            }
 
 
        echo "Flash requires that we output something or it won't fire the uploadSuccess event";
    }
    
    
 
 
    #   --------------- 
    #   MAIL FUNCTION
        function send_mail($subject="Email Notify",$message="") { 
            global $upload_notify_email ; 
            $from = 'SWFUpload@mailinator.com' ; 
            $return_path = '-f '.$from ;
            mail($upload_notify_email,$subject,$message,"From: $from\nX-Mailer: PHP/ . $phpversion()");
        }
 
    
    
?>

Re: PHP Upload Issues

Posted: Mon Jul 20, 2009 7:18 pm
by califdon
What does your email say?

Re: PHP Upload Issues

Posted: Mon Jul 20, 2009 7:29 pm
by beanboy3001
It isn't sending either.
But I figured I would tackle 1 issue at a time.
I know that php works with the server that I'm on because I have a php mail form on another part of the site.
The most important part that I need is the upload option. The email was a bonus.

Re: PHP Upload Issues

Posted: Mon Jul 20, 2009 10:54 pm
by califdon
My point is that if you're not getting the email, obviously the script is not running. So your challenge is to figure out why not. I know nothing about the particulars of your script, but the way I would debug it is to comment out about half of the code and put an echo statement somewhere in the other part, to see whether it will run with half of it not being interpreted. If the echo statement shows up on your screen, you know that somewhere in the part you commented out, there's a fatal error, so now you can narrow it down. If the echo statement doesn't show up, you know that somewhere in the part you DIDN'T comment out, there's a fatal error. Again, you've narrowed it down. Proceeding like this, you can eventually isolate the problem by either commenting out more or commenting out less. The other thing you can do is put the following 2 lines at the beginning of your PHP code:

Code: Select all

 
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
This won't always show you the errors, because if the parser can't understand your syntax, it can't even do that, but it's certainly worth trying.

Re: PHP Upload Issues

Posted: Tue Jul 21, 2009 8:00 am
by beanboy3001
Thank you,
It seems like obvious logic to me. I'm not sure why I didn't think about the fact that if the email didn't work either than something was wrong.
Thanks for answering. I'll post again later today telling if it works.