Jump to content

Image Upload


sblake161189

Recommended Posts

Hi Guys!  :)

 

I already have a database with a table that stores information about different franchises for the company like franchise name, address, tel, email etc etc. This works beautiful so I can CRUD this data.

 

However, now to be able to add the facility for each franchise to be able to upload their own image of the franchise itself and still be able to CRUD the data.

 

I have looked on the internet and found many scripts using BLOB etc but I can get it to link in with my existing table.

 

I'll show you the edit form that I have so far. (Pleas not Ter = territory, ie the territory that franchise covers.

 

<?php
include('config.php'); 
if (isset($_GET['Ter']) ) { 
$ter = (int) $_GET['Ter']; 
if (isset($_POST['submitted'])) { 
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } 
$sql= "UPDATE `ter` SET `Ter` =  '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' ,  `BranchAddress` =  '{$_POST['BranchAddress']}' ,  `BranchTel` =  '{$_POST['BranchTel']}' , `BranchEmail` =  '{$_POST['BranchEmail']}' , `BranchLink` =  '{$_POST['BranchLink']}' , `Theme` =  '{$_POST['Theme']}' , `LocalInfo` =  '{$_POST['LocalInfo']}' , `BranchInfo` =  '{$_POST['BranchInfo']}' WHERE `Ter` = '$ter' "; 
mysql_query($sql) or die(mysql_error()); 
echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />";  
} 
$row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' "));
?>

<form action='' method='POST'> 
<p><b>Territory:</b><br /><input name='Ter' type='text' value='<?= stripslashes($row['Ter']) ?>' size="3" readonly="readonly" />
<p><b>Branch Name:</b><br /><input name='BranchName' type='text' value='<?= stripslashes($row['BranchName']) ?>' size="50" /> 
<p><b>Address:</b><br />
  <textarea name='BranchAddress' cols="40" rows="5"><?= stripslashes($row['BranchAddress']) ?></textarea> 
<p><b>Telephone:</b><br /><input name='BranchTel' type='text' value='<?= stripslashes($row['BranchTel']) ?>' size="15" />
<p><b>Email:</b><br /><input name='BranchEmail' type='text' value='<?= stripslashes($row['BranchEmail']) ?>' size="50" />
<p><b>Link:</b><br /><input name='BranchLink' type='text' value='<?= stripslashes($row['BranchLink']) ?>' size="50" />
<hr />
<p><b>Your Single Webpage Options</b>
<p><b>Theme:</b><br />
  <input name='Theme' type='text' value='<?= stripslashes($row['Theme']) ?>' size="1" />
<p><b>Local Information:</b><br />
  <textarea name='LocalInfo' cols="85" rows="8" id="LocalInfo"><?= stripslashes($row['LocalInfo']) ?>
  </textarea>
<p><b>Franchise Information:</b><br />
  <textarea name='BranchInfo' cols="85" rows="8" id="BranchInfo"><?= stripslashes($row['BranchInfo']) ?>
  </textarea>
<p><b>Photo:</b><br />
  <label>
    <input type="file" name="photo" id="photo" />
  </label> 
  (Franchise Photo)  
<p><b>Downloads:</b><br />
  <label>
    <input type="file" name="download1" id="download1" />
  </label> 
  (S/O Mandate)
<p>
  <label>
    <input type="file" name="download2" id="download2" />
  </label>
  (Other Download)
<p>
  <label>
    <input type="file" name="download3" id="download3" />
  </label>
  (Other Download)
<p>
  <input type='submit' value='Save' />
  <input type='hidden' value='1' name='submitted' />
</form>

<? } ?>

 

It is the 'photo' file above that I want to be able to upload the image with. Is this the right way to do it?

 

Ignore the download1,2,3 bit.

 

Cheers, S

Link to comment
https://forums.phpfreaks.com/topic/228494-image-upload/
Share on other sites

quick google of php image upload revealed this page at position 1:

 

http://www.reconn.us/content/view/30/51/

 

it goes through upload, renaming the image file, and saving the image to a location on the server. the only part left out is storing the image name in MySQL, which is the easiest part of the whole thing.

Link to comment
https://forums.phpfreaks.com/topic/228494-image-upload/#findComment-1178187
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.