473,243 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,243 software developers and data experts.

Good image uploader with thumbnails?

I want to make a portfoliosystem where user can register and get their
own portfolio... I've started the developer work, but I'm stuck on the
image upload part... I'm experiencing some problems getting the picture
resized and thumbnailed... I'm on a apache server running php 5 with
8MB php_memory.

When uploading, the script works fine most times when uploading small
files (below 100kb and sometimes up close to 300kb too), but when
uploading files bigger than 300kb it only reloads the page, and the
form fields are empty.

Does any of you know of a smoothly working script for uploading,
resizing and thumbnailing? I need it to write a line to the database
too, but that's no problem writing... Excuse my bad english, but I'm
norwegian :)

If you're intrested, the code I have now is pasted below:



//Last inn global konfigurasjonsfil - denne filen må finnes for at
systemet skal laste
echo("global_config.php finnes ikke");

//Last inn globale funksjoner

echo("global_functions.php finnes ikke");

//Hent ut brukernavn

//Koble til databse

$dir = "temp/"; //Change this to the correct dir RELATIVE TO WHERE
THIS SCRIPT IS, or /full/path/

//MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
$types =
// Nothing to edit below here.

//Opprett thumbnail-funksjonen

function endre($name,$filename,$new_w,$new_h){
if (preg_match('/jpg|jpeg/',$system[1])){
if (preg_match('/png/',$system[1])){

if ($old_x > $old_y) {
if ($old_x < $old_y) {
if ($old_x == $old_y) {

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thum b_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
} else {
//Check to determine if the submit button has been pressed
if(isset($_POST['submit'])) {

//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $_FILES['upload']['name'];
$cat_id = $_POST['cat_id'];
$tittel = $_POST['tittel'];
$beskrivelse = $_POST['beskrivelse'];
$fullpath = "$dir$path/";
$temppath = "bilder/";
$fullpath = str_replace("..", "", str_replace("\.", "",
str_replace("//", "/", $fullpath)));
$clean_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_",
str_replace("%20", "_", strtolower($new_name) ) ) );

// lets see if we are uploading a file or doing a dir listing
//Sjekk MIME-typen
if ((in_array($_FILES['upload']['type'], $types)) and

//Opprett mapper som er nødvendige
if (!is_dir($fullpath)){
mkdir("$fullpath", 0777);
if (!is_dir("thumb/")){
mkdir("thumb/", 0777);
if (!is_dir("temp/")){
mkdir("temp/", 0777);
//Flytt filen til /temp-mappen
move_uploaded_file($tmp_name,$fullpath . $clean_name);

//Slett originalfilen
$ourFileName = "temp/$clean_name";
$ourFileHandle = fopen($ourFileName, 'w') or die("kunne ikke
&aring;pne fil for sletting");
$query = "INSERT INTO `portfolio_brukere_doffer` (`id`, `cat_id`,
`url`, `url_full`, `tittel`, `beskrivelse`, `om`) VALUES ('',
'$cat_id', 'thumb/thumb_$clean_name', 'bilder/$clean_name', '$tittel',
'$beskrivelse', '')";
mysql_query($query) or die('Error, insert query failed');
echo "$clean_name ble lagt til";

//Print Error Message
echo "<small>Filen
<strong><em>{$_FILES['upload']['name']}</em></strong> finnes fra
f&oslash;r av</small><br />";
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];

echo "Navn: $name<br />Type: $type<br />St&oslash;rrelse: $size<br
/>Tmp: $tmp";

} */
} else {
echo 'Ready to upload your file';
} ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"

<legend>Last opp bilde</legend>
<table border="0" cellspacing="0" cellpadding="0">
<td>Bilde som skal lastes opp </td>
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input type="file" name="upload" />&nbsp;</td>
<td><input name="tittel" type="text" maxlength="100">&nbsp;</td>
<select name="cat_id">
<option selected>Velg en kategori</option>
<option>- - -</option>
$kategorier = "SELECT * FROM `portfolio_cat` LIMIT 0 , 100";
$cat_resultat = mysql_query($kategorier);
while ($row= @mysql_fetch_array($cat_resultat)) {
$cat_id = $row["id"]; //hent ut kategori-id
$cat_navn = $row["name"]; //hent ut kategori-navn

//Send informasjonen ut til leseren
echo("<option value=\"$cat_id\">$cat_navn</option>");
$count++ ;
<td><textarea name="beskrivelse"></textarea></td>

<input type="submit" name="submit" value="Last opp" />

Jul 28 '05 #1
0 1771

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
by: Michael Satterwhite | last post by:
I'm opening a page that has a single image on it. I'd like to resize the window containing the image to the size of the image (slightly larger OK, not smaller). The width isn't a problem, but the...
by: grahamhe | last post by:
Hi, I have recently upgraded .NET from 1.0 to 1.1 and now an application I am writing is no longer uploading the files, any ideas? I have posted the relevant code below... <%@ Page...
by: PhoenixFalconhand | last post by:
Begginners' question: I am trying to make a small webform application that doesn't use frames. The application is supposed to show some thumbnails on the left, and whenever you click on one of...
by: IkBenHet | last post by:
Hello, I want to make thumbnails from images. I found this code and modified it and it works fine: <%@Import Namespace="System.Drawing.Imaging" %> <script language="VB" runat="server">...
by: Nak | last post by:
Hi there, I've come across quite an annoying bug after optimizing some of my code (which sounds quite strange I know), but take this for a description of my problem. * I have a background...
by: RE Kochanski | last post by:
I have attempted to use the CSS techniques from two or three sites to create a CSS only image gallery. I am muddling the affair by placing the thumbnails in one float, the page text in another...
by: ak1dnar | last post by:
Hi, Future Photo is using Basic uploader and advanced uploader to upload images to there albums, My question is how to build up this kind of advanced uploader in php. As i feel its related with ...
by: harikrishnan4u | last post by:
How can we check the image size in rad uploader this file uploader is in the rad editor??any one Know
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.