Jump to content

Unlink


jomagi

Recommended Posts

It dont show anything, all run normaly with delete mysql record and redirect on finish, just the files don't erase from server folder.

 

Alright, lets comment out 

header(sprintf("Location: %s", $deleteGoTo));

 

Then re-run the script with the code I gave you. Let's see if anything is displayed. As the script I gave you would not "error out", although it should output something and cause a header error since it does echo information out no matter what.

 

Given that, I do not think you updated the script properly on the site. Either it was uploaded to the wrong spot, or the wrong modified file was uploaded. As this should cause header errors since it outputs data before the header call.

Link to comment
Share on other sites

Let's try this now:

 

$logoname = $_SERVER['DOCUMENT_ROOT'] . '/' . $row["logotipo"];
if (file_exists($logoname)) {
   $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4);
   echo 'The permissions for the file ' . $logonname . ' are: ' . $fileinfo . '<br />';
   if (unlink($logoname)) {
          echo 'The file ' . $logoname . ' should be erased.<br />';
   }else {
          echo 'The file ' . $logoname . ' was not erased.<br />';
   }   
}else {
    echo 'The file does not exist!';
}

 

And see what spits out.

Link to comment
Share on other sites

The folder, maybe. The file is not. The file itself needs to be "writeable", which right now it is not, to be erased.

 

$logoname = $_SERVER['DOCUMENT_ROOT'] . '/' . $row["logotipo"];
if (file_exists($logoname)) {
   $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4);
   if ($fileinfo != "0777") 
       chmod($logoname, "0777");

   if (!unlink($logoname)) {
          echo 'The file ' . $logoname . ' was not erased.<br />';
   }   
}else {
    echo 'The file does not exist!';
}

 

Give that a try and see if it works.

Link to comment
Share on other sites

"The file /hsphere/local/home/dargil/dargil.pt/ was not erased."

 

How come you have an ending / after dargil.pt ? Where is that coming from....well either way let's try this:

 

$logoname = $_SERVER['DOCUMENT_ROOT'] . '/' . substr($row["logotipo"], 0, -1);
if (file_exists($logoname)) {
   $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4);
   if ($fileinfo != "0777") 
       chmod($logoname, "0777");

   if (!unlink($logoname)) {
          echo 'The file ' . $logoname . ' was not erased.<br />';
   }   
}else {
    echo 'The file does not exist!';
}

 

That should remove the ending slash. If the file actually does have that ending slash in it, then the issue is that. Files with ' and / tend to be very picky and can usually only manually be erased. I would suggest you filter your upload file names to remove or not allow those characters.

 

Sorry I did not catch that earlier.

Link to comment
Share on other sites

the / is from a folder, files doesn't have / ' " or spaces.

 

Full root from a file in server is for example:

 

"/hsphere/local/home/dargil/dargil.pt/dargilmusica/images/etiquetas/ex002.jpg"

 

Full root for internet is for example:

 

"http://www.dargil.pt/dargilmusica/images/etiquetas/ex002.jpg"

 

I give a try in last script and post the same:

 

"The file /hsphere/local/home/dargil/dargil.pt/ was not erased."

 

Link to comment
Share on other sites

Yes, database is ok

The store data look like this:

 

"images/etiquetas/ex002.jpg"

 

I highly doubt that, at least on your remote server, try this and see what it spits out:

 

echo 'The file name retrieved from the DB is: ' . $row["logotipo"] . " alternatively, if there is nothing there the DB column is either wrong, or there is no data for this row.<br />";
$logoname = $_SERVER['DOCUMENT_ROOT'] . '/' . $row["logotipo"];
if (file_exists($logoname)) {
   $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4);
   if ($fileinfo != "0777") 
       chmod($logoname, "0777");

   if (!unlink($logoname)) {
          echo 'The file ' . $logoname . ' was not erased.<br />';
   }   
}else {
    echo 'The file does not exist!';
}

 

If that is the case, figure out why you are not getting the correct information out of the DB, do you need to insert a test record, since this record should have been erased each time you ran the script previously?

Link to comment
Share on other sites

It show the next message:

 

"The file name retrieved from the DB is: alternatively, if there is nothing there the DB column is either wrong, or there is no data for this row.

The file /hsphere/local/home/dargil/dargil.pt/ was not erased."

 

The database table in server (i made site with mysql in server, not local) is ok and update each time I insert or delete record, I check in MySQL Query Browser.

In each new script I insert a new record (etiqueta) and then make the delete.

Link to comment
Share on other sites

Thanks to all for the help.

 

The problem are with the query.

 

I have just "etiquetas" that is the table name, and after did a echo to the query realize that it doesn't find database, so just change to "dargil_site.etiquetas" and it work fine.

 

So simple e so many time spend to guess, thanks to all, keep the good work!

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.