0

I am in the process of copying a website and its database structure. Everything has been working great except the uploading of pictures. The user can log in and upload a picture as an account picture. When the code is executed I just get a blank screen and have to start over. Any ideas why? Here is the code I am working with :

// make a note of the location of the upload form
 $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self .'editprofile.php'; //Working

$photourltest=$_FILES['photourl'];

if (($_FILES['photourl']['type'] != 'image/jpeg') && ($_FILES['photourl']['type'] != 'image/pjpeg')) {

    $photo=$_POST['photo'];
    if ($photo == "") {
        $photo = "http://www.somekindofsite.com/id/images/keys.jpeg";
    }
} else if ($_FILES['photourl']['error'] > 0) {
        echo 'Problem : ';
        switch ($_FILES['photourl']['error'])
        {
            case 1: echo 'File exceeded upload_max_filesize';
                    echo "Please press the back button to re-edit";
                    break;
            case 2: echo 'File exceeded max_file_size';
                    echo "Please press the back button to re-edit";
                    break;
            case 3: echo 'File only partially uploaded';
                    echo "Please press the back button to re-edit";
                    break;
            case 4: echo 'No file uploaded';
                    echo "Please press the back button to re-edit";
                    break;
            case 6: echo 'Cannot upload file: No temp directory specified';
                    echo "Please press the back button to re-edit";
                    break;
            case 7: echo 'Upload failed: Cannot write to disk';
                    echo "Please press the back button to re-edit";
                    break;
        }
        //exit;
} else {
    //put photo into directory
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
    $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'images/'; //*

    $upfile = $uploadsDirectory.$_FILES['photourl']['name'];
    $photo = 'http://www.somekindofsite.com/images/' .$_FILES['photourl']['name'];

    //moves the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES['photourl']['tmp_name'], $upfile)
    or error ('recieving directory insufficient permission', $uploadForm);
}
DolbyOver
  • 21
  • 6
  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. " –  Jul 01 '14 at 20:44

1 Answers1

0

There is no PHP function error() which are you are using at the end of the code you provided. This will cause a fatal error in PHP. Normally these are visible but I suspect you have error reporting turned off which will hide this message.

Turn on error reporting to see your error message. Then remove error() and replace it with a valid function to solve your issue.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Thank you that helped tremendously. What's weird is that I literally copied the above code from the website I am replicating, and the above code works perfect for that site. For my new site I just removed the error() function and was successfully able to upload the image path to my database but unfortunately can still not upload the actual image to the designated folder. – DolbyOver Jul 01 '14 at 21:19