Jump to content


Photo

Image Upload script problem...help


  • Please log in to reply
5 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 07 April 2006 - 02:25 AM

Alright, something is wrong with this script and I cannot figure it out, I just get the 'Could no move File' Error that I wrote myself....

<?php


// code that will be executed if the form has been submitted:

if ($submit) {

    // connect to the database

    require_once('dbconnect.php');
    $conn = db_connect();
    mysql_select_db("user_art");
    
    move_uploaded_file("'" . $_FILES['form_data'] . "'", "art/" . $_FILES['name'] . " ")
      or die('Could not move the file'); // Good to have error checking.
    
    $path = "art/" . $_FILES['name'] . " ";
    
    mysql_query("INSERT INTO user_art (description, path, filename, filesize, filetype)
        VALUES ('" . $_POST['form_description'] . "', '$path', '" . $_FILES['name'] . "','" . $_FILES['size'] . "','" . $_FILES['type'] . "')");

    $id= mysql_insert_id();
    print "<p>This file has the following Database ID: <b>$id</b>";

    mysql_close();

} else {

    // else show the form to submit new data:
?>

    <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
    File Description:<br>
    <input type="text" name="form_description"  size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="form_data"  size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>

<?php

}

?>

thank you in advance.

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 April 2006 - 03:05 AM

OK.

The $_FILES superdooperglobal is an aary of attributes for the uploaded file.

you MUST reference this array by the inputname of the form....

$_FILES['form_data']['name']
$_FILES['form_data']['type']

etc etc (often good to use the $_FILES['form_data']['error'] to check things!!)

Try that and it should improve things.

follow me on twitter @PHPsycho

#3 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 07 April 2006 - 03:13 AM

alright, well i changed everything so the $_FILES has ['form_data'] before the attribute.....but all that the $_FILES['form_data']['error'] gave me was '0' thats it....does that mean anything?

#4 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 07 April 2006 - 03:45 AM

alright, i messed with the script, and its still not working it dosent show the id, hence its not doing the query..... this is the new updated one:

<?php


// code that will be executed if the form has been submitted:

if ($submit) {

    // connect to the database


    require_once('dbconnect.php');
    $conn = db_connect();
    mysql_select_db("user_art");
    
    $updir = "art/";
    $finame = $_FILES['form_data']['name'];
    $path = $updir.$finame;
    
    move_uploaded_file($_FILES['form_data']['tmp_name'], $path)
      or die('Could not move the file <br> ' . $_FILES['form_data']['error']  .' '); // Good to have error checking.
    
    $descript = $_POST['form_description'];
    $fisize = $_FILES['form_data']['size'];
    $fitype = $_FILES['form_data']['type'];
    
    $result = mysql_query("INSERT INTO user_art (description, path, filename, filesize, filetype)
                    VALUES ('" . $descript . "', '" . $path . "', '" . $finame . "', '" . $fisize . "', '" . $fitype . "')");
                    
if($result) {
    $id= mysql_insert_id();
    print "<p>This file has the following Database ID: <b>$id</b>";
    }

    mysql_close();

} else {

    // else show the form to submit new data:
?>

    <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
    File Description:<br>
    <input type="text" name="form_description"  size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="form_data"  size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>

<?php

}

?>

what is wrong now?

#5 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 07 April 2006 - 11:48 AM

I'm sorry, but I really need help with this.

#6 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 April 2006 - 01:54 PM

does the file actually upload?

are you given any errors?

have you echoed out the query that is generatd so you can try to run directly in phpmyadmin?


follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users