By the way you should really be using DATE or DATETIME column type for storing dates.PHP Code:$q = "INSERT INTO uploaded_images (`filename`,`date`) VALUES ('$uploadFilename','".date(dMy)."')";
Printable View
By the way you should really be using DATE or DATETIME column type for storing dates.PHP Code:$q = "INSERT INTO uploaded_images (`filename`,`date`) VALUES ('$uploadFilename','".date(dMy)."')";
Thankyou!Quote:
Originally Posted by bokeh
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>
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.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?Quote:
Originally Posted by PJStew
thanks in advance :)
Your question is not really connected to image uploads. For maximum coverage it would probably be best if you started a new thread.Quote:
Originally Posted by PJStew
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?
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
That was just an example used in this script to ensure a unique file name.Quote:
Originally Posted by popcop
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
?>
Thank you so much! I kept trying to do it through the public_html folder instead of the www folder....Quote:
Originally Posted by john_de116
What is the diff between the two anyways?
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......
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.
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.
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!
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