Jump to content

Which picture for which row ?


bobahad

Recommended Posts

Hello guys,

I am storing bunch of information in a mysql database. The same form used to store the information also has an image field + browse to store a picture. But of course instead of storing the pic/logo in the database, it would make better sense to store it in a folder.

Now I run a loop to display all the values in the msyql table inside a well formatted table.

Each row in that table starts with the logo but how do I do it so the correct logo is near the correct row.

Please let me know if more clarification is needed and help is much appreciated.

Link to comment
Share on other sites

You can't store an image in the database, so of course you are going to have to put it in a folder. All you have to do is store the filename of the image in the database, then you will know exactly what image goes with which row.

 

So to display the images from the database, you would just do this.

 

<?php

echo "<img src='path_to_images/".$row['filename']."'>";

?>

Link to comment
Share on other sites

Do I need a seperate form to upload a file or should the same form work, this is what I currently have.

 

<h1>Add a Car</h1>

<FORM NAME="addcarform" enctype="multipart/form-data" METHOD="Post" ACTION="">

 

<TABLE>

<TR>

<TD><B>Type:</B></TD>

<TD><INPUT SIZE="6" TYPE="text" NAME="type" VALUE=""></TD>

</TR>

<TR>

<TD><B>Make:</B></TD>

<TD><INPUT TYPE="text" NAME="make" VALUE=""><br></TD>

</TR>

<TR>

<TD><B>Model:</B></TD>

<TD><INPUT TYPE="text" NAME="model" VALUE=""></TD>

</TR>

<TR>

<TD><B>Year:</B></TD>

<TD><INPUT SIZE="4" TYPE="text" NAME="year" VALUE=""></TD>

</TR>

<TR>

<TD><B>V.I.N #:</B></TD>

<TD><INPUT TYPE="text" NAME="vin" VALUE=""></TD>

</TR>

<TR>

<TD><B>Color:</B></TD>

<TD><INPUT SIZE="10" TYPE="text" NAME="color" VALUE=""></TD>

</TR>

<TR>

<TD><B>Cost:</B></TD>

<TD><INPUT SIZE="5" TYPE="text" NAME="cost" VALUE=""></TD>

</TR>

<TR>

<TD><B>Selling Price:</B></TD>

<TD><INPUT SIZE="5" TYPE="text" NAME="sellingprice" VALUE=""></TD>

</TR>

<TR>

<TD><B>Date Bought:</B></TD>

<TD><INPUT SIZE="20" TYPE="text" NAME="datebought" VALUE=""></TD>

</TR>

<TR>

<TD><B>Link to Pictures:</B></TD>

<TD><INPUT SIZE="33" TYPE="text" NAME="logolink" VALUE=""></TD>

</TR>

<TR>

 

<TD><input type="hidden" name="MAX_FILE_SIZE" value="30000" /><b>Upload Logo:</b></TD>

<TD><input  name="userfile" type="file" /></TD>

<TR/>

  <TR>

<TD><INPUT TYPE="submit" name="add" Value="Add Car"></TD>

</TR>

<TR>

<TD><INPUT TYPE="reset"></TD>

</TR>

</TABLE>

<br>

 

 

</FORM>

Link to comment
Share on other sites

Thanks guys and sorry for the trouble, one last question.

So does $_FILES['textboxname'] automatically extract the file name from c:/my documents/pictures/picture1.jpg ?

Cause when I hit browse, that's what it shows.

Sorry I am just new to this, first semester php.

Link to comment
Share on other sites

Why isn't this working?

 

function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){

    $details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.');

    $type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']);

    eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");');

    $thumbHeight = $details[1] * ($thumbWidth / $details[0]);

    $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);

    imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, 

    $details[0], $details[1]);

    eval('image'.$type.'($thumbImg, "$thumbDirectory/$imageName"'.

    (($type=='jpeg')?', $quality':'').');');

    imagedestroy($srcImg);

    imagedestroy($thumbImg);

}

 

foreach ($_FILES["filename"]["error"] as $key => $error) {

  if ($error == UPLOAD_ERR_OK) {

      $tmp_name = $_FILES["filename"]["tmp_name"][$key];

      $name = $_FILES["filename"]["name"][$key];

      move_uploaded_file($tmp_name, "data/$name");

      createThumbnail("/images", $name, "/images/thumbs", 120, 80);

      //120 = thumb width  ::  80 = thumb quality (1-100)

  }

}

 

$query2="INSERT INTO $Table (Filename) VALUES ('$name')";

print($query2);

 

 

and here's the form code

 

<TR>

 

<TD><input type="hidden" name="MAX_FILE_SIZE" value="30000" /><b>Upload Main Picture:</b></TD>

<TD><input  name="filename" type="file" /></TD>

<TR/>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.