SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Dromenail's Avatar
    Join Date
    Nov 2006
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Blank page with advanced upload script

    OK, When I started copying this script out i knew I'd go wrong somwhere but I dont know where I've gone wrong. The code is from a sitepoint book called
    " Build your own database dirven website using PHP & MySQL " by Kevin Yank

    Here it is
    PHP Code:
    <?php

    $dbcnx 
    mysql_connect("localhost""callum""callum");
    mysql_select_db("callum2");

    if ((
    $action == "view" or $action == "dnld")
        and 
    $id != "") {

    $sql "SELECT FlieName, MimeType, FileData
        FROM filestore WHERE ID = '
    $id'";
    $result = @mysql_query($sql);
    if (!
    $result) die("Database error » " mysql_error());

    $filename mysql_result($result,0,"FileName");
    $mimetype mysql_result($result,0,"MimeType");
    $filedata mysql_result($result,0,"FileData");

    if (
    $action == "dnld") {
        if (
    strpos($HTTP_USER_AGENT"MSIE"))
            
    $mimetype "application/x-download";
        else
            
    $mimetype "application/octet-stream";
    }
    header("Content-Disposition » filename=$filename");
    header("Content-Type » $mimetype");
    header("Content-Length » " strlen($filedata));

    echo(
    "$filedata);
    exit();

    }elseif (
    $action == "del" and $id !="") {

    $sql = "DELETE FROM filestore WHERE ID '$id'";
    $ok @mysql_query($sql);
    if (!
    $ok) die("Database error » " . mysql_error());

    header("
    Location » $PHP_SELF");
    exit();

    } elseif (
    $action == "ulfile" and $uploadfile """) {

        if (!
    is_uploaded_file($uploadfile))
        die(
    "$uploadfile Is not an uploaded file!");

    $tempfile fopen($uploadfile,"rb");

    $filedata fread($tempfile,filesize($uploadfile));

    $filedata addslashes($filedata);

    $sql "INSERT INTO filestore SET 
        FileName = '
    $uploadfile_name',
        MimeType = '
    $uploadfile_type',
        Description = '
    $desc',
        FileData = '
    $filedata'";

    $ok = @mysql_query($sql);
    if (!
    $ok) die("Database error storing selected file  » " .
        
    mysql_error());

    header("Location » $PHP_SELF");
    exit();

    }

    $sql "SELECT ID, FileName, MimeType, Description
        FROM filestore"
    ;
    $filelist = @mysql_query($sql)
        or die(
    Database error » " . mysql_error());
    ?>
    <html>
    <head>
    <link rel="
    stylesheet" type="text/css" href="style.css" />
    <title>
    »Kizo filestore
    </title>
    </head>
    <body>
    <b>»Kizo Filestore</b><br />
    <form action="
    <?=$PHP_SELF?>?action=ulfile" method="post"
        enctype="multipart/from-data">
    <p>Upload file to store »<br />
    <input type="file" name="uploadfile" /></p>
    <p>File description »<br />
    <input type="text" name="desc" maxlength="255" /></p>
    <p><input type="submit" name="go" value="Upload »" /></p>
    </form>

    <p>the following files are stored in our database »</p>
    <table width="85%" border="0" cellpadding="0"
        cellspacing="0">
    <tr>
      <th align="left">File Name</th>
      <th align="left">Type</th>
      <th align="left">File Description</th>
    </tr>
    <?php

    if (mysql_num_rows($filelist) > 0) {
        while (
    $f mysql_fetch_array($filelist)) {
              
    ?>
    <tr valign="top">
      <td nowrap>
        <a href="<?=$PHP_SELF?>?action=view&id=<?=$f['id']?>">
           <?$f['FileName']?></a>
      </td>
      <td nowrap>[<a href="<?=$PHP_SELF?>?action=dnld&id=<?=$f['id']?>">Download file</a> l <a href="<?=$PHP_SELF?>?action=del&id=<?=$f['id']?>"
        onClick="return confrim('Delete this file?');"
      >Delete file</a>]
      </td>
    </tr>

        <?php
            
    }
    }else{
        
    ?>
    <tr><td colspan="3" align="center">No files!</td></tr>
    <?php
    }
    ?>
    </table>
    </body>
    </html>
    any ideas?
    Callum Carolan

  2. #2
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see that he write an algarithm, coz he use
    "and or" , it must be "&&, ||"

    try to understand what the code do,
    Open Blocked website
    Open Blocked Website
    Knowledge Is Knowing That A Tomato Is A Fruit,
    Wisdom Is Not Putting It In A Fruit Salad.

  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I see several syntax errors.
    I'd recommend that you get yourself Zend Studio. (for all the good reasons)


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
  •