www.webdeveloper.com
Results 1 to 4 of 4

Thread: help debbugging

  1. #1
    Join Date
    Mar 2007
    Posts
    49

    help debbugging

    I'm getting this message after pressed upload button. Help please.

    Array ( )
    Warning: fread(): supplied argument is not a valid stream resource in C:\wamp\www\MyAdmintrator\Temp\addPhoto.php on line 7


    <?php
    if ($_POST['Submit']) {
    if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
    print_r($_FILES);
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("test");
    $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "rb"), $_FILES['file']['size']));

    $query = sprintf("INSERT INTO image(Image, FileType) VALUES('%s', '%s')", $photo, $_FILES['file']['type']);
    if (mysql_query($query)) {
    $messages[] = "Your files is successfully store in database";
    } else {
    $messages[]= mysql_error();
    }
    }
    else {
    $messages[]="The file is bigger than the allowed size please resize";
    }
    }
    ?>
    <html>
    <head>
    <title>Add Image</title>
    </head>
    <body>
    <?
    if (isset($messages)) {
    foreach ($messages as $message) {
    print $message. "<br>" ;
    }
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="form1">
    <input type="file" name="file">
    <input type="hidden" name="MAX_FILE_SIZE" value="96000">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    move the print_r to the top of our script rather than inside the if's
    also don't rely on the MAX_FILE_SIZE from the form that is a very easy value for a user to change if they want to.

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  3. #3
    Join Date
    Mar 2007
    Posts
    49
    Thanks for your help. But I tried to move Print_R on top of if and still get the same error message after I pressed upload button. Please if you've better concept to solve this problem let me know. Thanks again.

  4. #4
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    just looking on php.net it says you must have the MAX_FILE_SIZE before the file input this could be causing you the problems?
    try moving them around to see what happens.

    Scott.
    Close the windows and get to know your inner Penguin with Linux

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles