Jump to content

please help my code isnt working how it should


dassa

Recommended Posts

hi

i have a php script which takes from an image upload form, and processes using the following script

the user can upload for different images from a form which are copied from the temp folder into a created directory for that user.

it works fine but the problem occurs when the user goes back to update an image stored in the database

using the same form the new input over writes the previously uploaded file. therefore unless the user uploads all the images at once the missed out fields  overwrite the exsisting files with blank entry in the database and also removes the file from the user directory.

 

what i want to happen is for the file to remain and the entry for the the database field to stay the same if no file was added to the upload form. only for the fields which contain a new file to change

 

any help would be most useful

 

<?php

 

$err = 0;

 

  $dir = AddSlashes(htmlspecialchars($HotelID));

 

  if (is_dir ("template/$dir") == false){

 

    mkdir ("template/$dir", 0777);

 

  }else{

 

    exec ("rm -f template/$dir/*.*");

 

    $query = "delete from template where HotelID='$HotelID'";

 

    $result = dataQuery($query);

 

  }

 

  if ($logo_name <> NULL){

 

    list($width,$height,$type, $attr) = getimagesize($logo);

if ($width>160 || $height>140)

{

$err = 1;

}

else

{

    copy($logo,"template/$dir/" . "$logo_name");

}

 

  }

 

  if ($room_name <> NULL){

list($width,$height,$type, $attr) = getimagesize($room);

if ($width>300 || $height>200)

{

  $err = 2;

  }

else

{

    copy($room,"template/$dir/" . "$room_name");

}

 

  }

 

  if ($hotel_name <> NULL){

list($width,$height,$type, $attr) = getimagesize($hotel);

if ($width>300 || $height>200)

{

  $err = 3;

}

else

{

    copy($hotel,"template/$dir/" . "$hotel_name");

}

 

  }

 

  if ($banner_name <> NULL){

list($width,$height,$type, $attr) = getimagesize($banner);

if ($width>400 || $height>75)

{

  $err = 4;

}

else

{

    copy($banner,"template/$dir/" . "$banner_name");

}

 

  }

  //echo $dir;

  if($err == 0)

  {

  $query = "Insert into template values ('$HotelID','$logo_name','$room_name','$hotel_name','$banner_name','$back_color','$font_color')";

$result = dataQuery($query);

echo "The template has been saved! Please press the Back button in your browser.";

  }

  else

  {

  if($err==1)

{

echo "Logo image does not have the required size! Please press the Back button in your browser.";

}

else

{

if($err==2)

{

echo "Room image does not have the required size! Please press the Back button in your browser.";

}

else

{

if($err ==3)

{

echo "Accomodation image does not have the required size! Please press the Back button in your browser.";

}

else

{

if($err ==4)

{

echo "banner image does not have the required size! Please press the Back button in your browser.";

 

}

}

}

  }

 

}

 

 

 

 

 

?>

 

 

thanks

 

 

Link to comment
Share on other sites

This looks more like a VB script :)

 

You didn't include your html form or the image upload code but you can check to see if the file was uploaded with this code...

html:
<input type="file" name="image">

php:
if (!empty ($_FILES['image']['name'])){

     // Validate and Upload Code Goes Here

}

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.