www.webdeveloper.com
Page 5 of 23 FirstFirst ... 3456715 ... LastLast
Results 61 to 75 of 340

Thread: How to: Upload images using PHP

  1. #61
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    PHP Code:
    $q "INSERT INTO uploaded_images (`filename`,`date`) VALUES ('$uploadFilename','".date(dMy)."')"
    By the way you should really be using DATE or DATETIME column type for storing dates.

  2. #62
    Join Date
    Jun 2006
    Posts
    159
    Quote Originally Posted by bokeh
    PHP Code:
    $q "INSERT INTO uploaded_images (`filename`,`date`) VALUES ('$uploadFilename','".date(dMy)."')"
    By the way you should really be using DATE or DATETIME column type for storing dates.
    Thankyou!
    that got it. When you say using DATE or DATETIME column type for storing dates, do you meen change date into DATE or DATETIME in MySQL?

    Like this.
    Code:
    mysql> use images;
    Database changed
    mysql> show tables;
    +------------------+
    | Tables_in_images |
    +------------------+
    | uploaded_images  |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> explain uploaded_images;
    +----------+-------------+------+-----+---------+-------+
    | Field    | Type        | Null | Key | Default | Extra |
    +----------+-------------+------+-----+---------+-------+
    | id       | int(11)     | YES  |     | NULL    |       |
    | filename | varchar(50) | YES  |     | NULL    |       |
    | DATE     | varchar(50) | YES  |     | NULL    |       |
    +----------+-------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)
    
    mysql>

  3. #63
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by PJStew
    When you say using DATE or DATETIME column type for storing dates, do you meen change date into DATE or DATETIME in MySQL?
    Yes. At the minute you are using a varchar column. If you switch to DATE or DATETIME you can take advantage of MySQL formating of the query result.

  4. #64
    Join Date
    Jun 2006
    Posts
    159
    I don't quite understand how you display the images.

    What i after is a seperate page where it displays the images and you can flick through them using an next buton. Idealy I would like it so you could also say how much you like the image with maybe 1-10 using radios, a bit like hot or not.

    If anyone can tell me how to do any part of this it would be much apreciated!

  5. #65
    Join Date
    Jun 2006
    Posts
    159
    Quote Originally Posted by PJStew
    I don't quite understand how you display the images.

    What i after is a seperate page where it displays the images and you can flick through them using an next buton. Idealy I would like it so you could also say how much you like the image with maybe 1-10 using radios, a bit like hot or not.

    If anyone can tell me how to do any part of this it would be much apreciated!
    Can anybody help me with this? I'd also like the images to be diplayed in a random order if that is possible?

    thanks in advance

  6. #66
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by PJStew
    a seperate page where it displays the images and you can flick through them using an next buton. Idealy I would like it so you could also say how much you like the image with maybe 1-10 using radios, a bit like hot or not.
    Your question is not really connected to image uploads. For maximum coverage it would probably be best if you started a new thread.

  7. #67
    Join Date
    May 2004
    Posts
    288
    from reading this thread i have taken from it that id have to send the images from the uploaded folder to a database before i could actually display them on a web page.. is this correct?

    also... why does the code add 1155116715- to the start of my image name once ive uploaded it?

  8. #68
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by popcop
    from reading this thread i have taken from it that id have to send the images from the uploaded folder to a database before i could actually display them on a web page.. is this correct?
    The database is just used to keep a record of what images are in the upload directory and is just an extra.

    Quote Originally Posted by popcop
    also... why does the code add 1155116715- to the start of my image name once ive uploaded it?
    That was just an example used in this script to ensure a unique file name.

  9. #69
    Join Date
    Dec 2005
    Posts
    193
    Hi, I'm trying to get this to show the uploaded files but no matter what I try it will only show one file name, over and over.
    like xxx.jpg, xxx.jpg instead of xxx.jpg, yyy.jpg

    here is what I've done to the processor page to get there, but i'm stuck, any ideas?

    PHP Code:
    // make a unique filename for the uploaded file and check it is 
    // not taken... if it is keep trying until we find a vacant one
    foreach($active_keys as $key)
    {
        
    $now time();
        while(
    file_exists($uploadFilename[$key] = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'][$key]));
        
    $uploadFilenames[$key] = $now.'-'.$_FILES[$fieldname]['name'][$key];
        {
            
    $now++;
        }
    }

    // now let's move the file to its final and allocate it with the new filename
    foreach($active_keys as $key)
    {
        @
    move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
            or 
    error('receiving directory insuffiecient permission'$uploadForm);
    }
        

    {
        
        echo 
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
        
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
        
    '<html lang="en">'."\n".
        
    '    <head>'."\n".
        
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
        
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
        
    '    <title>Uploaded</title>'."\n\n".
        
    '    </head>'."\n\n".
        
    '    <body>'."\n\n".
        
    '    <div id="Upload">'."\n\n".
        
    '        <h1>Images Uploaded</h1>'."\n\n".
        
    '        <p>Your Image locations are: '."\n\n".
        
    '        ' $uploadFilenames[$key] . '...<br>'."\n\n".
        
    '        ' $uploadFilenames[$key] . '...<br>'."\n\n".
        
    '         <br>Thank You</p>'."\n\n".
        
    '     </div>'."\n\n".
        
    '</html>';
        exit;
    // end error handler

    ?> 

  10. #70
    Join Date
    May 2004
    Location
    The Big M
    Posts
    669
    Quote Originally Posted by john_de116
    Hi,
    Give the folder's permission 777 in FTP.
    Or entering into the cpanel->Files->www->Upload Folder--> Change the permission as 777.
    Then you can do it.
    $file__name="john.doc";
    move_uploaded_files($HTTP_POST_FILES(['file']['tmp_name']),'upoad_Files'.$filename);
    Do it like this way.
    Thank you so much! I kept trying to do it through the public_html folder instead of the www folder....

    What is the diff between the two anyways?
    <? Damn Browser Incompatibilities ?>
    Dell 1505~2.0 Core Duo~1 gig DDR2-533~ Radeon x1400(256mb)~ Hitachi 100gb 7200rpm
    <? Go Blue. ?>

  11. #71
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    www and public_html are just two differnt server set up optiong, Nothing to do with PHP Each can ber differnt with no difference to web operation.
    My server is /hosting/index.php......

  12. #72
    Join Date
    Sep 2006
    Posts
    3
    Hi hope I'm not too late?

    As part of a CMS it would be useful to be able to append specific file names when the user uploads a file.

    So for example as part of the HTML form you could have seven radio buttons - Monday - Sunday.

    So you choose a picture, click on a radio button - then the script uploads the image to your server as e.g. tuesday.jpg.

    Okay I know it would be very easy to just rename the file - but the idea of a CMS is to make everything as simple as possible.

    Can anybody help with the PHP? And if a file already exists on the server, would it automatically overwrite it without prompts.

    I've only tested this code locally - and yes it does just overwrite the existing file.

    Anyway I would love any feedback.

  13. #73
    Join Date
    Jul 2006
    Posts
    24
    Hi, if you want to keep things simple, why are you adding radio buttons for the days of the week? Why can't you use time()?
    That's bokeh's -the original coder- idea.

  14. #74
    Join Date
    Sep 2006
    Posts
    3
    Thanks Iapfama,

    I probably didn't understand properly. Is there a method that Bokeh has suggested?

    Let's say you have 7 jpegs on your server. Let us say you want to overwrite the one on the server named 'tuesday.jpg'. If I wanted to upload a picture that was already called file.jpg, I would like the option either by radio buttons or a drop down list to change the name of the file being uploaded - so it overwrites the one on the server.

    Those imges are the ones being pulled in via XML into Flash for example.

    Does this make sense?

    This is probably an over simplified way of doing it - is there a better, more conventional way?

    Let me know!

  15. #75
    Join Date
    Jul 2006
    Posts
    24
    You can try this:

    In your form file do a radiogroup like this:
    <label><input type="radio" name="weekDay" value="Monday">Monday</label>
    <label><input type="radio" name="weekDay" value="Tuesday">Tuesday</label>
    <label><input type="radio" name="weekDay" value="Wednesday">Wednesday</label>
    etc...
    get that value in your uploadProcessor file: $weekDay = $_POST['weekDay'].;

    After you do all the checks on the original file you re-name it in two steps:
    1) You need to know the extension of the file =>to get it susbstract the 4 las characters of the original file. ('.jpg' or '.gif') and for example you call it $extension.
    2) re-name it:
    $uploadFilename = $uploadsDirectory.$weekDay.$extension

    What I'm not sure is how you do the overwriting because in my case when I try to upload a file that already exists, it gives me problems. In that case, what I suggest you to do is to: a) find the existing matching file, b) re-name it, c) upload the new file.

    I hope this helps you

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