Hi, I want users on my website to upload their company logo (if they have one) while filling out my form. Right now i only have one row designated for the company logo called 'images' with the type set to BLOB. Is this adequate for both uploading images and displaying them on my website?

Another thing, I used dreamweaver's 'insert record' server behaviour to generate a script that causes my form to insert data into my database table. One line that I'm curious about is the following:

GetSQLValueString($_POST['upload'], "text"),

Do I need to change 'text' to something other then 'text'? I tried 'image' but that caused an error. Note that this line is giving me an error so something has to be done to it and it's obviously for the upload element in my form.

Are you set on actually storing the images in your database? have you considered, saving the images to the file system and storing the location of the image in your database instead? Each approach does have its own advantages.

I'm set set on that particular approach. How do i store the images to my file system and store the location of the images to my database?

How do i store the images to my file system and store the location of the images to my database

So the actual implementation depends on the server side scripting (php, asp.net, jsp), but the idea is to have an upload control on the page, capture the upload and save it to a folder on the web server or whatever storage is accessible from the web server. You then take the path of that location and file name and store it in one of your fields.

On a page where you want to display the image, you would do the reverse... read from the database, then attach that information to the 'src' attribute for the image element.

okay, how would i do that with php?

Hey PHP guys and gals... Some help here...

I found a recipe on that site you linked to me that almost solves my problem. But not quiet. I got the following code from that site:

<?php
// define a constant for the maximum upload size
define ('MAX_FILE_SIZE', 1024 * 50);

if (array_key_exists('upload', $_POST)) {
  // define constant for upload folder
  define('UPLOAD_DIR', '/path/to/images/');
  // replace any spaces in original filename with underscores
  $file = str_replace(' ', '_', $_FILES['image']['name']);
  // create an array of permitted MIME types
  $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg',
'image/png');

  // upload if file is OK
  if (in_array($_FILES['image']['type'], $permitted)
      && $_FILES['image']['size'] > 0 
      && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    switch($_FILES['image']['error']) {
      case 0:
        // check if a file of the same name has been uploaded
        if (!file_exists(UPLOAD_DIR . $file)) {
          // move the file to the upload folder and rename it
          $success =
move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR .
$file);
        } else {
          $result = 'A file of the same name already exists.';
        }
        if ($success) {
          $result = "$file uploaded successfully.";
        } else {
          $result = "Error uploading $file. Please try again.";
        }
        break;
      case 3:
      case 6:
      case 7:
      case 8:
        $result = "Error uploading $file. Please try again.";
        break;
      case 4:
        $result = "You didn't select a file to be uploaded.";
    }
  } else {
    $result = "$file is either too big or not an image.";
  }
}
?>

How do i get this code to rename the image to something unique and store the name in my table row labeled images?

Member Avatar for LastMitch

How do i get this code to rename the image to something unique and store the name in my table row labeled images?

I don't know.

The reason why is that you are the only one who know what table and column in your database.

You are asking me a question about rename an image and store in your table in your database?

This is the only code your provide:

GetSQLValueString($_POST['upload'], "text"),

The example from the link show what columns are in the table in the database.

I'm pretty sure that you would want to use a generate a random number and/or use a portion of the current date/time so you can rename or just append this to the file name. Or, you can keep another field in a database table and use a standard naming convention and just append a sequence number.

So your question is how to include this naming component in your PHP code.

So your question is how to include this naming component in your PHP code.

Yes

The reason why is that you are the only one who know what table and column in your database.

Oh sorry. The database is biz, the table is ads, and the row is images.

This is the only code your provide

In my last post I provided the code I recieved from:
Click Here

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.