Jump to content

unlinking a file suddenly stopped working. Any ideas why?


sonnieboy

Recommended Posts

// Check to see if any images need deleting
if(isset($_POST['delete']) && !empty($_POST['delete'])) {

	// whilelisted table columns
	$fileColumnsInTable[]	= 	'BidIDFile';
	$fileColumnsInTable[]	= 	'TabSheet';
	$fileColumnsInTable[]	= 	'SignInSheet';
	$fileColumnsInTable[]	= 	'XConnect';
	$fileColumnsInTable[]	= 	'Addend1';
	$fileColumnsInTable[]	= 	'Addend2';
	$fileColumnsInTable[]	= 	'Addend3';
	$fileColumnsInTable[]	= 	'Addend4';
	$fileColumnsInTable[]	= 	'Addend5';
	$fileColumnsInTable[]	= 	'Addend6';

	// Loop through the post to assign delete fields
	foreach($_POST['delete'] as $fileCol => $fileColumn) {
			// If set and allowed to be delete
			if(in_array($fileCol, $fileColumnsInTable)) {
					// Save the columns to temp
					$fileColumns[]		=	$fileCol;
					// Save the file spots as blanks in the main post
					$_POST[$fileCol]	=	'';
				}
		}

	// Check that there are files requiring attention
	if(isset($fileColumns)) {

			$sql_statement	=	"select ".implode(", ",$fileColumns)." from bids where ID = ?";
			$query			=	sqlsrv_query($conn,$sql_statement,array($strId));

			// No files, just return
			if($query === false)
				return $errors	=	'file_fail_link';

			$files 			= 	sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);

        //print_r($files);


			// loop over the files returned by the query

			foreach ($files as $file) {

					$thisfile = __DIR__.'/uploads/'.$file;



					//delete file

					if(is_file($thisfile))

						unlink($thisfile);

				}

        }
}
if(isset($_POST['delete']))
	unset($_POST['delete']);
    {
    //echo "This is an update statement";
	// This will generate an update query
	$update	=	$BidSet->SaveData($_POST,array("Id"))
						->SaveFolder('../uploads/')
						->AddFiles('BidIDFile')
						->AddFiles('item')
						->AddFiles('SignInSheet')
						->AddFiles('TabSheet')
						->AddFiles('Xcontract')
						->where(array("Id"=>$_POST["Id"]))
						->UpdateQuery()
						->statement;

	//echo '<pre>';
	//print_r($update);
	//echo '</pre>';
	
//*****************************************************************************************************

    <td>
     <table border="0">
      <tr>
        <td class="td_input_form">
	         <?php
	         // if the BidIDFile is empty,
	         if(empty($result["BidIDFile"]))
	         {
	             //then show file upload field for Bid File
	             echo '<input type="file" name="BidIDFile[]" size="50">';
	         }
	         else
	         {
	             // Bid file already upload, show checkbox to delete it.
	             echo '<input type="file" name="BidIDFile[]" size="50"> <br />';
	 	             echo '<input type="checkbox" name="delete[]" value="'.$result["BidIDFile"].'"> (delete)
                     <a href="http://KitApps/train/Boards/uploads/'.$result["BidIDFile"].'" target="_blank" onclick="window.open (this.href, \'child\', \'height=800,width=850,scrollbars\'); return false" type="application/octet-stream">'.$result["BidIDFile"].'</a>';
	         }
	         ?>
        </td>
       </tr>
      </table>
     </td>

Dear all,

 

I have some code snippets.

 

Complete code is very long.

 

The code does insert and update.

 

You can unlink (delete) a file only without updating any records or you unlink a file as well as update records.

 

This has worked very well before but suddenly, it is no longer unlinking a file but record updates still work fine.

 

Any ideas why?

 

Please see code snippet.

 

Thanks a lot in advance.

Edited by sonnieboy
Link to comment
Share on other sites

Great suggestion, iarp!!

 

This is what it shows:

E:\inetpub\wwwroot\Train\Boards\admin/uploads/0

The path should actually be:

E:\inetpub\wwwroot\Train\Boards/uploads/

And the issue is here:

$thisfile = __DIR__.'/uploads/'.$file;

How do I change this to correspond with 

E:\inetpub\wwwroot\Train\Boards/uploads/

Thank you

Link to comment
Share on other sites

If magic constants is actually enabled it returns that folders directory path

 

You can define it if it's not.

if (!defined('__DIR__')) {
   define('__DIR__', dirname(__FILE__));
}

if you have some sort of rewrite rule for the site the code is still seeing it's original path.

 

You can easily set this manual versus using __DIR__

$thisfile = 'E:\inetpub\wwwroot\Train\Boards/uploads/'.$file;

Hard to suggest anything beyond that because do not know anything else about your file structure or rewrite rules.

Link to comment
Share on other sites

Array ( [] => 0 ) 
// Check to see if any images need deleting
if(isset($_POST['delete']) && !empty($_POST['delete'])) {

	// whilelisted table columns
	$fileColumnsInTable[]	= 	'BidIDFile';
	$fileColumnsInTable[]	= 	'TabSheet';
	$fileColumnsInTable[]	= 	'SignInSheet';
	$fileColumnsInTable[]	= 	'XConnect';
	$fileColumnsInTable[]	= 	'Addend1';
	$fileColumnsInTable[]	= 	'Addend2';
	$fileColumnsInTable[]	= 	'Addend3';
	$fileColumnsInTable[]	= 	'Addend4';
	$fileColumnsInTable[]	= 	'Addend5';
	$fileColumnsInTable[]	= 	'Addend6';

	// Loop through the post to assign delete fields
	foreach($_POST['delete'] as $fileCol => $fileColumn) {
			// If set and allowed to be delete
			if(in_array($fileCol, $fileColumnsInTable)) {
					// Save the columns to temp
					$fileColumns[]		=	$fileCol;
					// Save the file spots as blanks in the main post
					$_POST[$fileCol]	=	'';
				}
		}

	// Check that there are files requiring attention
	if(isset($fileColumns)) {

			$sql_statement	=	"select ".implode(", ",$fileColumns)." from bids where ID = ?";
			$query			=	sqlsrv_query($conn,$sql_statement,array($strId));

			// No files, just return
			if($query === false)
				return $errors	=	'file_fail_link';

			$files 			= 	sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);

print_r($files);

I am really confused now.

 

How did this work before?

 

When I run above code and do print_r($files);

 

I get this:

 

Array ( [] => 0 )

 

How did this work before?

 

What changed?

Link to comment
Share on other sites

	if(isset($_POST["Id"]))
	{
		$strId = $_POST["Id"];
		//echo $strId;
	}
	If ($strId == "") {
	//echo "This is an insert statement";
	// This will generate an insert query
	$insert	=	$BidSet->SaveData($_POST)
						->SaveFolder('../uploads/')
						->AddFiles('BidIDFile')
						->AddFiles('item')
						->AddFiles('SignInSheet')
						->AddFiles('TabSheet')
						->AddFiles('Xcontract')
						->InsertQuery()
						->statement;

	// Check that statement is not empty
	if($insert != false) {
			sqlsrv_query($conn,$insert); ?>
			<br><br><br><br><br>
			<div class="error_button">
			 <div style="float: right; font-size: 18px; font-weight: bold; color: #FFF;" onClick="DisplayErrorTag('close')">x</div>
			  <?php render_error(array("title"=>"Bid Successfully Saved!","body"=>'Go back to <a href="currentrecs.php">Solicitation screen</a>')); ?>
		     </div>

		  <?php
			$err	=	false;
		}


	//echo '<pre>';
	//print_r($insert);
//	echo '</pre>';
    }
else
{
// Check to see if any images need deleting
---
---

Hi guys, thanks again for your help.

 

With mac_gyver first, the $strid is coming from the top of the code above.

 

When I echo it, it shows the correct Id.

 

QuickOldCar, neither the database nor any of the tables is corrupt.

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.