Hi!
I have been working a little with php code and my current project is to make something like deviantart ( http://www.deviantart.com).
The difference is that the image will be put in a table data at the same row with the information to it ( input from html text fields).
But now comes the question:
This image in the table data should be an image link to a new page where the image shows up.
Which means that I also need some way to automatically make a thumbnail of the image.
Help in any way is very much appreciated!!
Uploading image into page table
Moderator: General Moderators
Uploading image into page table
Hi,
at first i think storing images directly in the db is a *bad* idea. It's much better and more performant if you store the image in the file system and the "/usr/local/Web/shared/images/your_image" path in the db.
Here's a short (and working) example:
This snippet needs an enctype=\"multipart/form-data\" form in front with an input field like this:
It checks wether the file size is not larger than your MAX_FILE_SIZE (to be defined as an hidden field in the form, or, much better and safer, in the php.ini) and wether the files upload has worked; then, it moves the re-named file to its destination directory and chmod it to be redable for all.
To generate a thumb of this image, you could use the
Hope this helps a little. Greez,
-bluenote
at first i think storing images directly in the db is a *bad* idea. It's much better and more performant if you store the image in the file system and the "/usr/local/Web/shared/images/your_image" path in the db.
Here's a short (and working) example:
Code: Select all
<?php
if (isset ($_POST["is_uploaded_file"])) {
$filetype = $_FILES["your_image"]["type"];
$filesize = $_FILES["your_image"]["size"];
$filename = $_FILES["your_image"]["name"];
$filetemp = $_FILES['your_image']['tmp_name'];
$fileerror = $_FILES['your_image']['error'];
$tmp_size = $filesize / 1024;
if (($filetype=='image/jpeg') || ($filetype=='image/pjpeg') || ($filetype=='image/jpg')) {
$extension = ".jpg";}
else if ($filetype=='image/gif') {
$extension = ".gif";}
$filename_prefix = "your_name";
$filename = "$filename_prefix$extension";
if ($filesize <= $max_file_size) {
if (is_uploaded_file($filetemp)){
move_uploaded_file($filetemp,"$uploaddir_staff/".$filename_new_b."$extension");
chmod ("/$uploaddir_staff/$filename_new_a", 0644);
$query = "INSERT INTO ...}
else { ...}}}
?>Code: Select all
<?php
echo "<input type="radio" name="is_uploaded_file[]" value="1"> <input type="file" name="your_image" value="" size="20">";
?>To generate a thumb of this image, you could use the
functions documented at http://www.php.net to generate the thumb for display on the webpage; the link you can generate using the storage path and some environment vars.getimagesize
imagecopyresized
Hope this helps a little. Greez,
-bluenote