SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Local php file upload problems

    I have Apache2/mySQL 3.23.39/PHP4 installed on my home computer (Dell inspirion 8200 laptop, 512Mb ram, 1.8Mhz intell) for php debugging purposes. I am having a problem with file uploads. I create a form with a file upload field, but the file doesn't seem to be passes to the script. File uploads are enabled in the php.ini file. Below is the actual script with the error messages. Any help would be appreciated.


    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <?php
    function randomString($len) { 
       
    srand(date("s")); 
       
    $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
       
    $str=""
       while(
    strlen($str)<$len) { 
          
    $str.=substr($possible,(rand()%(strlen($possible))),1); 
       } 
       return 
    $str
    }  
    mysql_connect('localhost');
    mysql_select_db('alumni');

    if(isset(
    $HTTP_POST_VARS[submit]))
    {
    echo 
    "size: ".$HTTP_POST_VARS[userfile_size];
    do
        {
        
    $name randomString(5).strstr('$HTTP_POST_VARS[userfile_name]',".");
        
    $result mysql_query("SELECT filename from photos where filename = '$name'");
        } while(
    mysql_num_rows($result) > 0);
        
    $path "/photos/".$name;
    echo 
    "PATH: ".$path."<BR><BR>";
    copy($HTTP_POST_VARS[userfile], $path);
    mysql_query("INSERT into photos values(NULL, '$HTTP_POST_VARS[name]', NULL, '$HTTP_POST_VARS[description]', '$name', '$name')") or die("UNABLE TO ADD SQL ENTRY:".mysql_error());
    echo 
    "copy successful!";
    }
    ?>

    <body bgcolor="#FFFFFF" text="#000000">
    <form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post" enctype="multipart/form-data">
      <table width="31%" border="1">
        <tr> 
          <td width="27%">Your Name: </td>
          <td width="4%">&nbsp;</td>
          <td width="69%">
            <?php echo $uname?><input type="hidden" name="<? echo $uname?>" value="garret">
          </td>
        </tr>
        <tr> 
          <td width="27%">&nbsp;</td>
          <td width="4%">&nbsp;</td>
          <td width="69%">&nbsp;</td>
        </tr>
        <tr> 
          <td width="27%">Today's Date:</td>
          <td width="4%">&nbsp;</td>
          <td width="69%">
            <?php echo date("l: F j, Y"); ?>
          </td>
        </tr>
        <tr> 
          <td width="27%">&nbsp;</td>
          <td width="4%">&nbsp;</td>
          <td width="69%">&nbsp;</td>
        </tr>
        <tr> 
          <td width="27%">Description</td>
          <td width="4%">&nbsp;</td>
          <td width="69%"> 
            <textarea name="description" cols="30" rows="5"></textarea>
          </td>
        </tr>
        <tr> 
          <td width="27%">&nbsp;</td>
          <td width="4%">&nbsp;</td>
          <td width="69%">&nbsp;</td>
        </tr>
        <tr> 
          <td width="27%">Photo File:</td>
          <td width="4%">&nbsp;</td>
          <td width="69%"> 
            <input type="file" name="userfile" size="30">
          </td>
        </tr>
        <tr> 
          <td colspan="3"> 
            <div align="center">
              <input type="submit" name="submit" value="Submit">
              <input type="reset" name="Submit2" value="Reset">
            </div>
          </td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    Script Output
    ---------------------
    size: PATH: /photos/7Xsni

    Warning: Unable to open '' for reading: Permission denied in C:\Apache\Apache2\htdocs\photouploader.php on line 30
    -- sometimes I feel as though the gene pool could use a little chlorine.

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    copy($HTTP_POST_VARS[userfile], $path);

    should be

    copy($HTTP_POST_FILES['infile']['name']);

    see this for more info
    http://www.php.net/manual/en/features.file-upload.php

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, you should use move_uploaded_file() instead of copy().
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •