Change the file extension where the images are stored.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mike1234
Forum Newbie
Posts: 4
Joined: Thu Jul 10, 2014 5:59 am

Change the file extension where the images are stored.

Post by mike1234 »

Hi, I am building a basic art gallery for a friend who requires images to be uploaded onto a database and displayed. I have managed to get the crux of it working but I cant figure out how to change the file extension where the images are stored. I would like the images to be stored in a file called 'images' nad would like the extension to be put in place for you so you can simply browse you computer for the desired img . Any help would be much appreciated.

Code: Select all

<?php
extract($_REQUEST);

mysql_connect("localhost", "root", "password") 	or die(mysql_error());
mysql_select_db("test")            or die(mysql_error());

if( isset($submit) ) {
	$status = "";

	if( $title=="" ) {
		$status = "Please enter the art title.<br>";
	} else {
		// Connect to the database and insert the new artist
		if( isset( $id) && $id!="" ) {
			$sql = "UPDATE Art SET title='$title', " .
					"price='$price', description='$description', image='$image', artist_id='$artist_id'" .
					"WHERE id='$id'";
		} else {
			$sql = "INSERT INTO Art (title, price, description, image, artist_id ) ".
				   "VALUES ('$title', '$price', '$description', '$image', '$artist_id' )";
		}

		mysql_query( $sql )	or die(mysql_error());

		$status = "SUCCESSFULLY updated $title";
	}
} elseif ( isset($id) ) {

	$sql = "SELECT Art.title, Art.description, Art.price,
					Art.image, Art.artist_id
					FROM Art, Artist WHERE Art.artist_id=Artist.id AND Art.id='$id'";
	$resultset = mysql_query( $sql )	or die(mysql_error());
	$row = mysql_fetch_assoc( $resultset );
	extract( $row );

} else {
	$id=""; $title=""; $description=""; $price=""; $image=""; $artist_id=0;
}

?>
<? include("admin_header.php") ?>

<h1>Art Update Screen</h1>

<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
<input type="hidden" name="id" value="<?=$id?>">
<table>
  <? if (isset($status)) {?>
  	<tr><td colspan="2"><b><?=$status?></b><br><br></td></tr>
  <? } ?>
  <tr><td>Title</td><td><input type="text" name="title" value="<?=$title?>" /></td></tr>
  <tr><td>Artist</td>
  	<td><select name="artist_id">
		<option value="">Please Select</option>
		<?php
			$sql = "SELECT * FROM Artist";
			$resultset = mysql_query( $sql )	or die(mysql_error());
			while( $artist = mysql_fetch_assoc( $resultset ) ) {
				if ( $artist['id'] == $artist_id ) $check=" selected=\"SELECTED\" "; else $check="";
				print '<option value="' . $artist['id'] . "\" $check >" . $artist['name'] . "</option>\n";
			}
		?>
  	</select></td>
  </tr>
  <tr><td>Description</td><td><textarea rows="10" cols="60" name="description"
  			value="<?=$description?>" ><?=$description?></textarea></td></tr>
  <tr><td>Price</td><td><input type="text" name="price" value="<?=$price?>" /></td></tr>
  <tr><td>Image</td><td><input type="file"  name="image" value="<?=$image?>" />
	<small>(Path to the file relative to the root of the website)</small></td></tr>

  <tr><td colspan="2"><input type="submit" name="submit" value="Submit"/></td></tr>

</table>

</form>





<? include("admin_footer.php") ?>
Last edited by Celauran on Thu Jul 17, 2014 6:27 am, edited 1 time in total.
Reason: Please wrap your code in syntax tags
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Change the file extension where the images are stored.

Post by Christopher »

I think you are asking about doing the file upload part. See the docs and then come back if you are having problems:

http://php.net/manual/en/features.file-upload.php
(#10850)
Post Reply