#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    3
    Rep Power
    0

    Upload File - Access Forbidden! Error 403


    Hi everyone,

    So I am a newbie and this my first post. First of all, I am a beginner in PHP, still learning stuff.

    and, I am using :

    XAMPP 1.8.1
    Apache 2.4.3
    MySQL 5.5.27
    PHP 5.4.7
    phpMyAdmin 3.5.2.2
    Win 7 OS
    Google Chrome

    Recently, I created a PHP page to upload an image file and save it on my computer. This is the code :

    PHP Code:
    ?><html>
    <head>
    <title>Add Picture</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <?php 
    require "config.php";
    require 
    "globalVars.php";
    error_reporting(0);
        
    $studentID=1;

    if (isset(
    $_POST['submit'])) {
    $image_tmpname $_FILES['picture']['name'];
    $imgdir "pictures/";
    $imgname $imgdir.$image_tmpname;
    if(
    move_uploaded_file($_FILES['picture']['tmp_name'], $imgname))
    {
    list(
    $width,$height,$type,$attr)= getimagesize($imgname);
    switch(
    $type)
    {
     case 
    1:
      
    $ext ".gif"; break;
     case 
    2:
      
    $ext ".jpg"; break;
     case 
    3:
      
    $ext ".png"; break;
     default:
       echo 
    "Not acceptable format of image";
    }

    $last_pic_id 1;
    $newfilename $imgdir.$last_pic_id.$ext;
    rename($imgname,$newfilename); 
    }
    ?>

    <h1>Picture Added! </h1>
    <a href="JavaScript:window.close()"> <button name="cancel" value="cancel">Close Window</button> </a> 

    <?php 
     


     else 
     {    
     
    ?>

    <div>
    <h1>Upload Picture</h1>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data" id="form1"> 
    picture: <input type="file" name="picture" id="picture"><br> 
    </form>
    <button type="submit" name="submit" form="form1" value="Register">Add</button>
    <a href="JavaScript:window.close()"> <button name="cancel" value="cancel">Cancel</button> </a>
    </div>
    <?php
     
    }
     
    ?> 
    </body>
    </html>
    But as I try to run it, I get an error :

    Access forbidden!

    You don't have permission to access the requested object. It is either read-protected or not readable by the server.

    If you think this is a server error, please contact the webmaster.

    Error 403

    localhost
    Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7


    I saw a few threads regarding this and tried a few things like changing the directory access and changing a few config files, but I cannot get it to work. So, if you are aware of this problem, could you please tell me what to do (in layman terms).

    Thank you very much.
    Last edited by requinix; January 18th, 2013 at 06:08 PM. Reason: added php tags
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    That message is from Apache, not PHP. Have you taken a look at Apache's error logs to see why it's complaining?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    That message is from Apache, not PHP. Have you taken a look at Apache's error logs to see why it's complaining?
    Thanks for the quick reply. BTW, this is the error I get :


    [core:error] [pid 5920:tid 1724] (20024)The given path is misformatted or contained invalid characters: [client ::1:49507] AH00127: Cannot map POST /php/%3C?%20echo%20$_SERVER['PHP_SELF'];%20?%3E HTTP/1.1 to file, referer: http://localhost/php/test1.php

    Its weird because I used the form code other times and it works fine.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    Code:
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data" id="form1">
    You need to use the long-form tags.
    Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data" id="form1">
    They're not enabled for your setup so the action of the form was literally "<? echo $_SERVER['PHP_SELF']; ?>" - it wasn't being parsed by PHP.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    3
    Rep Power
    0
    Oops..that's really silly of me. Thanks a lot!

IMN logo majestic logo threadwatch logo seochat tools logo