SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question file not moving into upload directory

    hey folks,
    i m trying to make a little script for my first upload thingy and its going fine but it doesn't upload the file into told dir. the dir also exist and so does it echo me success msg but its not uploaded.here is the code
    Code PHP:
    <?php
    $type = $_FILES['upload']['type'];
     
    $size = $_FILES['upload']['size']."Kb";
     
    $nam =  $_FILES['upload']['name'];
     
    $dir_name = $_FILES['upload']['tmp_name'];
    $error = $_FILES['upload']['error'];
     
    if($error > 0){
    echo "Error submitting your file" .$error;
    }
    else
    {
    move_uploaded_file ($nam,"uploaded/".$dir_name);
    echo "uploaded!";
    }
    ?>
    i got another question too. i have a table made calles images and i want this script to also insert its reference into mysql how will i do that.....thnx in advance
    All those who wander aren't lost.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've mixed up a couple variables. See here for an example and more info
    http://www.php.net/manual/en/feature...ost-method.php

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    what abt my other question?
    All those who wander aren't lost.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you ever used mysql from within php before? Do you have a database and table created already?

  5. #5
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    php.net hmmm i never get wht they say. coz they say it hard. can u tell me where i m wrong?
    All those who wander aren't lost.

  6. #6
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yep i have a database. which has table images. in which it has id, listing_id(relational), image which is longblob. how do i send the iage which i moved into upload folder
    All those who wander aren't lost.

  7. #7
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    You've mixed up a couple variables. See here for an example and more info
    http://www.php.net/manual/en/feature...ost-method.php
    thanks mate i got it fixed. btw mysql problem is still unsolved. wht shld i do?
    All those who wander aren't lost.

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The usage of move_uploaded_file() is
    PHP Code:
    $success move_uploaded_file($filename_current_location$filename_new_location);
    if (
    $success) {
        echo 
    'moved';

    The current location of the uploaded file is $_FILES['upload']['tmp_name']. In your code, you seem to think this is a directory name, which it is not. It is the directory and filename.

    The manual provides some sample code which you should study and carefully compare to you own code.

    As for storing this in a database...you generally just store the filename of the image in the database, and store the actual file on the filesystem(in your uploads dir). A longblob column is a bit excessive to store a filename(although it would work). Consider making the column a varchar named image_filename, and then you just store the new filename in the database.

  9. #9
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i got all wht u said abt moving but can u please show me a code example of how to insert filename into mysql table with my example continuation.? thnx in advance
    All those who wander aren't lost.

  10. #10
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Any help? I have uploaded file into a permanent location how wil now insert its file name in mysql table so it gove me bank when I lot at a text it gives me the xorrosppndenset data
    All those who wander aren't lost.


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
  •