Hi All, I have been trying to create a php page that will upload a image, create a thumbnai and process a sql query, all automatically.
I have attached the two files. The form page (show-addrecord2.php) and the processing page (do_addrecord2.php).

The sql statement works fine. I am just having problems with the image upload and thumbnail creation part. I will also need the image and thumnail names to be added to the database as is in the sql query. I have tried a few things but cant seem to get it to work.

The problem seems to be at the point of upload.

I also should mention that the upload script is going to be in the admin folder of my script where the images will be in the images folder (not in admin/images - just /images). I hope you understand what I am trying to say. Also the links MUST remain reletive, just incase I install my script somewhere else.

Any help is greatly apreciated.

Dani AI

Generated

This thread shows the SQL part is fine and the break is around the upload/thumbnail steps. correctly called out a likely variable-name confusion, and is right to insist on using $_FILES (not the old $HTTP_POST_FILES). Below is a concise, reliable workflow and the key checks to get a single-image upload + thumbnail working from an admin folder while keeping image paths relative.

First, a short checklist to debug quickly:

  • Confirm the HTML form uses enctype="multipart/form-data" and the file input name matches what your PHP reads.
  • Dump $_FILES (e.g., print_r($_FILES)) to see error, tmp_name, size, and original name.
  • Verify upload_max_filesize, post_max_size, and writable permissions on ../images and ../images/thumbs.
  • Use move_uploaded_file() (it returns true/false) and check $_FILES['yourfield']['error'] === UPLOAD_ERR_OK.

A minimal safe pattern for naming/moving the upload (use in your processing script):

$name = preg_replace('/[^A-Za-z0-9._-]/', '', basename($_FILES['image']['name']));
$unique = time() . '_' . uniqid();
$destDir = __DIR__ . '/../images/';
$dest = $destDir . $unique . '_' . $name;
if ($_FILES['image']['error'] === UPLOAD_ERR_OK && move_uploaded_file($_FILES['image']['tmp_name'], $dest)) {
    // create thumbnail and save to ../images/thumbs/
}

For thumbnailing use getimagesize() to detect type, then imagecreatefrom..., imagecreatetruecolor(), imagecopyresampled() and imagejpeg/png() to save. Always free resources with imagedestroy().

Store only the relative filename/path in the database (not the server absolute path), sanitize names, and use prepared statements (PDO) for the SQL insert. If problems persist, check PHP error logs, enable errors for local testing, and test each step (file arrival, move, thumbnail) separately. For reference see the PHP file-uploads guide and GD image functions: PHP file uploads and PHP GD.

Recommended Answers

All 8 Replies

After a quick scan of your code, I suspect you are mixed up with two variables $newname and $image_name .

Forgive me if I'm wrong.

wulawula, The upload an thumbnail creation was taken form a tutorial that said it was supposed to work. I didn't test it before trying to integrate it into my script. So I don't know what the script should look like. I will continue to try different things though.

maxabet,
I actually have already read that thread, but was trying to get the script to do more. so, trying to make things easy, i downloaded one script that said it did what I wanted.

maxabet, I noticed something when going thru the other thread. The do_addrecord.php file that I uses a definition $img_name, but I don't see how or where that would be defined. Should I have a line near the top of the file that looks like this.

$img_name = $HTTP_POST_FILES;

I will go ahead and try it. The worst thing that could happen is it won't work.

i have an upload class if you want it. i created it to upload mulitple files and i also added a thumbnailing capability.

also $HTTP_POST_FILES is outdated. use $_FILES

kkieth29, I am interested in anything that will help me get this script going. Whether it is fixing this page or creating a new one. If you look at the do_addrecord.php page there is a couple of comment areas that specify where the image upload and processing script is. The important part is that the script is functional. I need the script to upload the image to (../images) folder and create a thumbnail and place that in the (../images/thumbs) folder. Then it needs to place the image and thumbnail images into the sql database.

Thanks for the help in advanced.

Does anyone have any help they can offer. I have tried a few things but can't get it to work. I'm stumped myself. Any Help is appreciated.

wow, sorry. been really busy with work. i will pm you the file as soon as i can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.