www.webdeveloper.com
Page 3 of 23 FirstFirst 1234513 ... LastLast
Results 31 to 45 of 340

Thread: How to: Upload images using PHP

  1. #31
    Join Date
    Sep 2005
    Posts
    1,634
    Quote Originally Posted by Sheldon
    store in a database and display the results where you want
    Do you know what function (code) to use if I would like to store files like e.g. images and what function to use for showing results?

  2. #32
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    well sorry i didnt really answer that very well, its been a long day

    If it were me and i havnt really looked at the code,
    but here
    PHP Code:

    // now let's move the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
        
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess); 
    I would add a mySQL insert script

    like this

    PHP Code:

    // now let's move the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
     
    //in addition to Bokeh's script you can insert each record into a database.

    $q "INSERT INTO table_name (`filename`,`date`) VALUES ('$uploadFilename',$date(dMy))"
    $s mysql_query($q);
    //if an error
    echo(mysql_error());

    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess); 

    and to display it would be a simple select script
    Last edited by Sheldon; 03-29-2006 at 02:17 AM.

  3. #33
    Join Date
    Apr 2006
    Posts
    2
    I suck at this. I'm more than a newbie, I'm a baby. I want to create a webpage that will allow a friend of mine to upload pictures using my website. I have read so much on formhandlers and php that now I am dizzy and even more confused. Is there someone out there that can help me make this webpage along with step by step instructions on how to impliment it. I use frontpage 2003. I also need it to be able to do multiple files. thank you

  4. #34
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    then dump frontpage and download bokehs multiple upload script and put it in your root dir. It will just work as long as you have php enabled on your server.

  5. #35
    Join Date
    Sep 2004
    Location
    Sunbury, PA
    Posts
    70
    Quote Originally Posted by toplisek
    Would you like FTP view or showing results on web site?
    I would like the results on the web site...more specifically to show on the page once uploaded.

    I figured that it would have to go into a database, but I am a rookie at databases.

    How would I get the pics that were uploaded to view on a page in real-time?
    Harry Kerstetter
    President
    Tylivia Web Design
    Browser: Firefox 2 beta 2
    Resolution: 1440 X 900
    Development Tools:
    Macromedia/Adobe Studio 8
    Adobe Illustrator CS
    SWiSH Max
    PHP Designer 2005
    Favorite Quote:"In completing one discovery we never fail to get an imperfect knowledge of others of which we could have no idea before, so that we cannot solve one doubt without creating several new ones." - Joseph Priestly, 1786

  6. #36
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    Refer to my post following toplisek's reponse. assuming you konw how to set up a database and have access to a mySQL database. Thats would be the first thing to check.

    then you want something like this.

  7. #37
    Join Date
    Apr 2006
    Posts
    26

    sql update problem

    Hi,

    OK, the image uploads ok, now I want to stick the filename into an existing row field. I don't get an error and the redirect works after the upload. Also I don't want to insert the whole path just the filename, am I using $uploadFilename ?

    My code is:
    PHP Code:
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to the success page.
    // But first add the image filename to the database
    require_once('includes/connect.php');
    $regid $_SESSION['ladyid'];
    $sql "UPDATE femaleusers SET image = '$uploadFilename' WHERE id = '$regid'";  
    header('Location: ' $uploadSuccess); 
    $regid holds the correct value and so does $uploadFilename as I echo'd them out to test.

    Many thanks if anyone can shed some light on this!

  8. #38
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Are you actually running the query, because the the query in your post is followed by header(Location:...) which in therory would cause a user abort.

  9. #39
    Join Date
    Apr 2006
    Posts
    26
    Yes, thanks.... although now I have the whole path and file name, like 'C:\blah\file.jpg'.

    Which variable should I use??
    Last edited by housey; 04-10-2006 at 05:30 PM.

  10. #40
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742

  11. #41
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    I thought this was a sticky?

    as Bokeh said, You need to run the query before sending them away with a header request.

    PHP Code:
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to the success page.
    // But first add the image filename to the database
    require_once('includes/connect.php');
    $regid $_SESSION['ladyid'];
    $sql "UPDATE femaleusers SET image = '$uploadFilename' WHERE id = '$regid'";  
    mysql_query($sql);//run the query
    echo(mysql_error));//echo any errors
    header('Location: ' $uploadSuccess); 
    $_SESSION['ladyid']; ?? what are you building? a porn site?
    Last edited by Sheldon; 04-10-2006 at 08:58 PM.

  12. #42
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742

  13. #43
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    Quote Originally Posted by Sheldon
    $_SESSION['ladyid']; ?? what are you building? a porn site?
    He should post the URL so we can check the code and make sure it is standards compliant!

    Answers to all your questions can be found at: PHP Manual

  14. #44
    Join Date
    Apr 2006
    Posts
    26
    @ALL
    Thanks for all the help on this...

    Where are those backslashes coming from?
    Sorry, my mistake when typing... more like C:/blah/file.jpg

    mysql_query($sql);//run the query
    echo(mysql_error));//echo any errors
    header('Location: ' . $uploadSuccess);
    I've now got the query running, if I put echo(mysql_error));//echo any errors in there I get an error with header('Location... saying header already sent... anyway it DOES now insert the filename in the correct field in the db but I have the whole upload path, I just want file.jpg but couldn't see what variable to use instead of $uploadFilename.

    $_SESSION['ladyid']; ?? what are you building? a porn site?
    Hehe... nope, not quite.. its a site for introductions more than anything... the ladies are all Thai.

    Thanks again for all the help....
    Last edited by housey; 04-11-2006 at 05:50 AM.

  15. #45
    Join Date
    Apr 2006
    Posts
    26
    hi,

    I know I haven't looked at this in awhile but I just thought i'd post my solution, simple for a non-newbie but I thought someone might find it useful.

    I added an extra variable after the while loop (for giving the file a unique name):

    PHP Code:
    //name var for image
    $imagename $now.'-'.$_FILES[$fieldname]['name']; 
    This gives me a variable of just the filename so I can insert it in the image field in the db with the sql query:

    PHP Code:
    $sql "UPDATE femaleusers SET image = '$imagename' WHERE id = '$regid'";  
    mysql_query($sql);//run the query 
    Not rocket science but maybe helps someone...
    Last edited by housey; 04-29-2006 at 10:27 AM.

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