1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

read(): supplied argument is not a valid

Discussion in 'PHP' started by advancedfuture, Mar 19, 2007.

  1. #1
    I am getting the following error in my little applet to upload images to my database.

    The script connects to the database no problem. It even creates a new entry. But the entry is blank, and my browser spits out the above mentioned error. Whats wrong in my code?

    submit.php

    <form method="post" action="upload.php" enctype="multipart/form-data">
    Description:<br>
    <input type="text" name="form_description" size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
    <br>File to upload:<br>
    <input type="file" name="form_data" size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>
    Code (markup):
    upload.php

    <?php
    mysql_connect("localhost","jason","password");
    mysql_select_db("test");
    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
    $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
    $id= mysql_insert_id();
    print "<p>File ID: <b>$id</b><br>";
    print "<p>File Name: <b>$form_data_name</b><br>";
    print "<p>File Size: <b>$form_data_size</b><br>";
    print "<p>File Type: <b>$form_data_type</b><p>";
    print "To upload another file <a href=http://192.168.1.66/submit.php> Click Here</a>";
    ?>
    Code (markup):
     
    advancedfuture, Mar 19, 2007 IP
  2. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #2
    Line 4 must be

    $data = addslashes(fread(fopen($_FILES['form_data'], "r"), filesize($_FILES['form_data'])));

    Try after editing and let me know if it works :D
     
    designcode, Mar 19, 2007 IP
    advancedfuture likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    ^^ Neither. It should be:

    
    $data = addslashes(fread(fopen($_FILES['form_data']['name'], "r"), filesize($_FILES['form_data']['name'])));
    
    PHP:
    or $_FILES['form_data']['tmp_name'] if you haven't moved the file yet.
     
    nico_swd, Mar 20, 2007 IP
  4. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), filesize($_FILES['form_data']['tmp_name'])));
     
    jitesh, Mar 20, 2007 IP