Jump to content

update stored image filename


ianhaney50

Recommended Posts

Hi

 

I am winning I think

 

I have got the records displayed for the current user logged in so basically they can only see their submitted listings and just working on the edit of them so the current user logged in can update their listing and is all working apart from the update of the images

 

the images are stored by the file name on the database and then gets moved onto the server so the actual images are not stored on the database only the file names are and the images are moved onto the server, hope that makes sense

 

what I can't do at the mo is work out how to update the file names of the images on the database and update on the server

 

I get the following error

 

Notice: Undefined index: photo on line 209 and line 211

 

the coding for them lines are below

$pic1= basename($_FILES['photo']['name'][0]);

$pic2= basename($_FILES['photo']['name'][1]);

The rest of the coding below that is

if(!empty($_FILES['photo']['tmp_name']))
{
	
	// Number of uploaded files
	 $num_files = count($_FILES['photo']['tmp_name']);

	 /** loop through the array of files ***/
	 for($i=0; $i < $num_files;$i++)
	 {
		 // check if there is a file in the array
		 if(!is_uploaded_file($_FILES['photo']['tmp_name'][$i]))
		 {
			 $messages[] = 'No file uploaded';
		 }
		 else
		 {
			 // move the file to the specified dir
			 if(move_uploaded_file($_FILES['photo']['tmp_name'][$i],$target.'/'.$_FILES['photo']['name'][$i]))
			 {
			
				 $messages[] = $_FILES['photo']['name'][$i].' uploaded';
				
			 }
			 else
			 {
				 // an error message
				 $messages[] = 'Uploading '.$_FILES['photo']['name'][$i].' Failed';
			 }
		 }
	 }

The update query is below

// save the data to the database
 mysql_query("UPDATE privatelistings SET listingtitle='$listingtitle', make='$model', model='$model', exteriorcolour='$exteriorcolour', enginesize='$enginesize', fueltype='$fueltype', yearregistered='$yearregistered', transmission='$transmission', mileage='$mileage', nodoors='$nodoors', bodystyle='$bodystyle', price='$price', photo='$pic1', photo1='$pic2' WHERE id='$id'")
 or die(mysql_error()); 

I am going to be updating to mysqli just want to get it working first

 

My HTML form coding is below

<form action="" method="post" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<?php echo $id; ?>"/>
 <div>
 <strong>Listing Title: *</strong> <input type="text" name="listingtitle" value="<?php echo $listingtitle; ?>"/>
 <br/>
 <strong>Make: *</strong> <input type="text" name="make" value="<?php echo $make; ?>"/>
 <br/>
 <strong>Model: *</strong> <input type="text" name="model" value="<?php echo $model; ?>"/>
 <br/>
 <strong>Exterior Colour: *</strong> <input type="text" name="exteriorcolour" value="<?php echo $exteriorcolour; ?>"/>
 <br/>
 <strong>Engine Size: *</strong> <input type="text" name="enginesize" value="<?php echo $enginesize; ?>"/>
 <br/>
 <strong>Fuel Type: *</strong> <input type="text" name="fueltype" value="<?php echo $fueltype; ?>"/>
 <br/>
 <strong>Year Registered: *</strong> <input type="text" name="yearregistered" value="<?php echo $yearregistered; ?>"/>
 <br/>
 <strong>Transmission: *</strong> <input type="text" name="transmission" value="<?php echo $transmission; ?>"/>
 <br/>
 <strong>Mileage: *</strong> <input type="text" name="mileage" value="<?php echo $mileage; ?>"/>
 <br/>
 <strong>Number of Doors: *</strong> <input type="text" name="nodoors" value="<?php echo $nodoors; ?>"/>
 <br/>
 <strong>Body Style: *</strong> <input type="text" name="bodystyle" value="<?php echo $bodystyle; ?>"/>
 <br/>
 <strong>Price: *</strong> <input type="text" name="price" value="<?php echo $price; ?>"/>
 <br/>
 <strong>Photo One:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'>
 <br>
 <strong>Photo Two:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'>
 <br>
 <input type="submit" name="submit" value="Submit">
 </div>
 </form>

sorry was not sure what other I need to show, so you guys get the idea?

Link to comment
Share on other sites

I am not sure I understand the question.  You want to rename image files that exist on the server? and then change them in the database so they match?  If so, there should never be a need to do that.  You should be creating a unique image name for each image uploaded.  The user never needs to know this name, only the browser.  The only thing the user would need to know is the captions, comments, etc.


To answer the question explicitly = rename()

Link to comment
Share on other sites

Hi jcbones

 

Thank you for replying, do appreciate it

 

Yeah sorry that is it, rather than replacing, should be a unique image name for each image so say if they have two current images stored, image1 and image2 then the user updates their listing and uploads the new images imagenew1 and imagenew2, they they should be stored on the database and server instead of image1 and image2, that make sense

 

is it done via the rename link you put just above?

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.