473,385 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How delete old updated images with their Alternates?

10
Hi, i wanna delete old updated images with considering its index in array.
i use global $oldimg = array() for storing their names but when i use theme at line 105-108 below, they aren't set;
here is my form:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. global $oldimg;
  3. $oldimg = array();
  4. //action: edit news     
  5. if (isset($_GET['id'])) {
  6.     $NewsID = (int)$_GET['id'];
  7.     if ($NewsID == 0) {
  8.         $rdir = '<META HTTP-EQUIV="Refresh" CONTENT="1.4;URL=panel-news.php">';
  9.         die($rdir);}
  10.  
  11. //get user from the database and put data into $_POST variables.
  12.     //Include database connection details
  13.     require_once('../config.php');    
  14.     //Connect to mysql server
  15.     $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  16.     if(!$link) {
  17.          die('Failed to connect to server: ' . mysql_error());
  18.                 }
  19.     //Select database
  20.      $db = mysql_select_db(DB_DATABASE);
  21.      if(!$db) {
  22.             die("Unable to select database");
  23.                 }
  24.     $rs = mysql_query("SELECT  newsimg1, newsimg2, ".
  25.     " newsimg3 FROM news WHERE id = $NewsID");
  26. if (mysql_num_rows($rs) == 0) die('no such a news!');
  27.     $row = mysql_fetch_assoc($rs);
  28.     $oldimg[0] = $row['newsimg1'];
  29.     $oldimg[1] = $row['newsimg2'];
  30.     $oldimg[2] = $row['newsimg3'];
  31. }
  32. ?>
  33. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"
  34.              enctype="multipart/form-data">
  35.                 <input type=file name="file[]" size=20 
  36.                 accept="image/jpg,image/jpeg,image/png">
  37.                 <input type=file name="file[]" size=20 
  38.                 accept="image/jpg,image/jpeg,image/png">
  39.                 <input type=file name="file[]" size=20 
  40.                 accept="image/jpg,image/jpeg,image/png">
  41.                 <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
  42.                 <input type="hidden" name="NewsID" 
  43.                 value='<?php echo (isset($NewsID))?$NewsID:"0";?>'>
  44.                 <input type="submit" value="edit" id="save"  name="save"/>
  45.             </form>
  46.             <?php
  47.             if (isset($_POST['save']) && isset($_POST['NewsID'])){
  48.                 $NewsID = (int)$_POST['NewsID'];
  49.               //Include database connection details
  50.               require_once('../config.php');
  51.               //Connect to mysql server
  52.               $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  53.               if(!$link) {
  54.                    die('Failed to connect to server: ' . mysql_error());
  55.                           }
  56.               //Select database
  57.               $db = mysql_select_db(DB_DATABASE);
  58.               if(!$db) {
  59.                   die("Unable to select database");
  60.                         }
  61.               //max fle size value
  62.               $max_file_size = 2097152;
  63.               //Global newsimg
  64.               global $newsimg;global $ctr;
  65.               $ctr = 0;
  66.               //timestamp to make files unique names
  67.               $timestamp = time();
  68.               //destination folder path
  69.               $destpath = "../Dir/Newsimg/";
  70.               //looping each file or image from the form
  71.               while(list($key,$value) = @each($_FILES["file"]["name"])) {
  72.               //check if any empty or errors
  73.               if(!empty($value)){
  74.               if ($_FILES["file"]["error"][$key] > 0) {
  75.               $edir ='<div id="fail" class="info_div">';
  76.               $edir .='<span class="ico_cancel"><strong>';
  77.               $edir .="err : ".  $_FILES["file"]["error"][$key]  .'</strong></span></div>';
  78.               echo($edir);
  79.               } else {
  80.               //add the timestamp to filename
  81.               $file_name = $timestamp.$_FILES['file']['name'];
  82.               //temp name from upload form,  key of each is set
  83.               $source = $_FILES["file"]["tmp_name"][$key] ;
  84.               //getting the file type
  85.               $file_type = $_FILES["file"]["type"][$key];
  86.               //placing each file name into a variable
  87.               $filename1 = $_FILES["file"]["name"][$key];
  88.               //lowering the file names
  89.               $filename = strtolower($filename1);
  90.               //adding timestamp to front of file name
  91.               $filename = "$timestamp$filename";
  92.               ++$timestamp;
  93.               if ($file_type != "image/jpeg" && $file_type != "image/png" && $file_type != "image/jpg") {
  94.                 die("
  95.                 <div id='fail' class='info_div'>
  96.                 <span class='ico_cancel'><strong>
  97.                 Invalid Format!</strong></span><br />
  98.                 <a href=\"javascript: history.go(-1)\">Retry</a>
  99.                 </div>"); }
  100.              //moving the file to be saved from the temp location to the destination path
  101.               move_uploaded_file($source, $destpath . $filename);
  102.               //the actual final location with timestamped name
  103.               $final_file_location = "$destpath$filename";
  104.               if (file_exists($final_file_location)) {
  105.                   if (isset($oldimg[$ctr])) {
  106.                       chdir('../Dir/Newsimg/');
  107.                       echo $oldimg[$ctr];
  108.                       unlink($oldimg[$ctr]);}
  109.                   $newsimg[$ctr] = $filename;
  110.                   $ctr++;
  111.  
  112. ?>
Feb 13 '11 #1
0 1146

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stokesy | last post by:
I am running a web page that has multiple web cams. The users are given ftp accounts to upload their web cam images every 30 seconds. What I want to do is instead of having the "refresh" in the...
4
by: greyseal | last post by:
I've gone around and around this thing for the last day or so. Using WIA, I can take and copy images from my Nikon D2H. However, when I attempt to delete the image I find that that capability is...
2
by: Alex | last post by:
I have a web application hosted on the server's F:\www directory. I have images stored on the file system at E:\Images. I have the website shared thru IIS pointing to the F:\www directory. 1.)...
5
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from...
2
by: Tom | last post by:
I need to be able to reference some images stored in my VB.NET program. Normally, I would load the images into an ImageList control and use them from there (these are going to be icons). However, I...
16
by: Frankie | last post by:
Hello: I'm coding a website which allows the owner to make add/change/deletes to his product database, which includes product images stored separately on the server. I have coded the Delete page...
4
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
4
by: Andrea Scharfe | last post by:
Hi there, I am writing a PHP script which generates some charts using gnuplot. This generates quite a large number of temporary image files. My problem is that I do not know how to delete these...
3
by: Jankie | last post by:
Ok,I now realized that imagecopyresize does not actually resize original image for good,but just resizes the display. I can live with that. Can someone help me to get this piece of code save the...
13
by: mac | last post by:
hi all, im creating a form wich wil upload images to a folder and their names and other details to a database. im able to do uploading but my delete function is not working, please can anybody...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.