SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uploading a file

    well, here we go again, after crawling trough the forum and reading like 50 posts on the same topic, I'm still stuck. There are no error msg's, but the picture is not uploaded, and $image is empty.

    PHP Code:
    <html>
    <head>
    <title>DivX Database</title>
    <body bgcolor=black link=yellow alink=yellow vlink=yellow text=white>
    <center><h1>DIVX DATABASE</h1></center>
    <?
    $db 
    mysql_connect(secret);
    mysql_select_db(kris_template,$db);
    if (
    $submit) {
     
    $uploaddir '/home/kris/public_html/tutorials/images/'
    $uploadfile $uploaddir$HTTP_POST_FILES['userfile']['name']; 
    $name = ("images/" $HTTP_POST_FILES['userfile']['name']); 
    move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadfile); 
    $image=$HTTP_POST_FILES['userfile']['name'];
            
    $sql "INSERT INTO tutorials (id, url, name, beskrivelse, tutorial, category, dadded, siteurl, hits) VALUES ('NULL','$image','$name','$beskrivelse','$tutorial','$category','CURDATE','$siteurl', 'NULL')";
            
    mysql_query($sql);
            echo 
    MYSQL_ERROR();
     
            echo 
    "$file_realname <center>Your data was sent! Thanks!<br><br>Back to the <a href=\"admin.php\">List</a>
    <br><br>DivX Database &copy; 2001 by <a href=\"mailto:webmaster@konsoll.net\">Webmaster</a>"
    ;
            }
    else {
    ?>
    <form method="post" action="<? echo $PHP_SELF ?>">
    <table border="0" align="center">
    <tr>
    <td>Title</td>
    <td><input type="text" name="name" value="<? echo $name ?>" size="50"></td>
    </tr>
    <tr>
    <td>Type</td>
    <td><select name="category" size="1">
    <option value="photoshop-effects-tutorial">photoshop-effects-tutorial
    <option value="photoshop-text-effects-tutorial ">photoshop-text-effects-tutorial 
    <option value="photoshop-photo-effects-tutorial ">photoshop-photo-effects-tutorial 
    <option value="photoshop-photo-retouch-tutorial ">photoshop-photo-retouch-tutorial 
    <option value="photoshop-web-layouts-tutorial">photoshop-web-layouts-tutorial 
    <option value="photoshop-web-graphics-tutorial ">photoshop-web-graphics-tutorial 
    <option value="photoshop-color-tutorial">photoshop-color-tutorial 
    <option value="photoshop-buttons-tutorial">photoshop-buttons-tutorial 
    <option value="photoshop-textures-patterns-tutorial">photoshop-textures-patterns-tutorial 
    <option value="photoshop-drawing-tutorial">photoshop-drawing-tutorial 
    <option value="photoshop-basic-tutorial ">photoshop-basic-tutorial 
    </select></td>
    </tr>
    <tr>
    <td>Beskrivelse</td>
    <td><input type="text" name="beskrivelse" value="<? echo $beskrivelse ?>" size="50"></td>
    </tr>
    <tr>
    <td>author</td>
    <td><input type="text" name="tutorial" value="<? echo $tutorial ?>" size="10"></td>
    </tr>
    <tr>
    <td>Siteurl</td>
    <td><input type="text" name="siteurl" value="<? echo $siteurl ?>" size="50"></td>
    </tr>
    <tr>
    <td>
    picture:</td>
    <td><input type="file" name="userfile" size="25"></td>
    </tr>
    </table>
    <br>
    <table border="0" align="center">
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Submit">
    <input type="reset" name="B2" value="Reset"></td>
    </tr>
    <tr>
    </table>
    </form>
    <br><br>DivX Database &copy; 2001 by <a href="[email="webmaster@konsoll.net"]mailto:webmaster@konsoll.net">Webmaster</a[/email]>
    <?
    }
    ?>
    </body>
    </html>

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this
    HTML Code:
    <form method="post" action="<? echo $PHP_SELF ?>" [B]enctype="multipart/form-data"[/B]>

  3. #3
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope, still not uploading anything.

  4. #4

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does print_r($HTTP_POST_FILES) say?

  5. #5
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    Array ( [userfile] => Array ( [name] => 2273.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpjBpyMx [error] => [size] => 2829 ) ) 
    hmms.. so the problem is actually that it can't temp upload to /tmp? any way to use another dir for temp files than that?

  6. #6

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, according to this output the file was successfully uploaded. What does move_uploaded_file return? Check that the permissions of the destination directory are properly set.

  7. #7
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it working, the bloody problem was that I wasn't thinking about the /tmp dir, and a chmod fixed everything. Thanks alot

  8. #8
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is right form!!!
    PHP Code:

    <?php
    $db 
    mysql_connect(secret);
    mysql_select_db(kris_template,$db);
    if(isset(
    $_POST["your_submit_button_name"])) insert_f();
    function 
    insert_f()
    {
    if(
    $image!="")
    {
    $name $_POST["name"]; 
    $beskrivelse $_POST["beskrivelse"];
    $tutorial $_POST["tutorial"];
    $category $_POST["category"];
    $siteurl $_POST["siteurl"];
    $uploaddir ''// your full path to upload directory starting with (example): d:/inetpub/webs/wwwyoursitecom/images
    $uploadfile $uploaddir$_FILES['userfile']['name'];  
    $image $_FILES['userfile']['name'];
    $sql "INSERT INTO tutorials VALUES ('NULL','$image','$name','$beskrivelse','$tutorial','$category','CURDATE','$siteurl', 'NULL')";
    $resultat mysql_query($sql);
    mysql_close($connect);
    echo 
    "Data inserted sucessfully!";
    } else {
    echo 
    "Problem inserting data!";
    }
    if (
    move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
       echo 
    "<font color='#ff0000'>File is valid, and was successfully uploaded.</font><br><br>";
    } else {
       echo 
    "<font color='#ff0000'>Possible file upload attack!</font><br><br>";
    }
    ?>
    cya


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
  •