Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts

    upload works but can not delete file due to spaces.. i think

    the following code for some reason puts a _ in place of the .

    the files in the directory are named ok, file1.jpg file2.jpg and so on.

    the source code prior to clicking the delete button shows all the files correctly formed.

    the uploaddir is also correct. just the . being changed to a _

    why would that be?



    foreach($_POST as $key => $val) {
    if ($key != "*.*" && $key != "*" && $key != "d") {
    //delete file from folder if exists !
    unlink($uploaddir . $key);
    echo($uploaddir . $key."<br><br><br><br>");
    echo($key.' Deleted<br>');
    mysql_query("DELETE FROM `images` WHERE `filename` ='" . $key . "' LIMIT 1;") or die(mysql_error());
    }
    }
    Last edited by jasonc310771; 01-03-2008 at 09:41 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    whats your $uploaddir look like that? Trailing slash, no trailing slash?

    What does your form look like?

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    this is my upload and delete file.


    <?
    $uploaddir = "/home/mysite/public_html/images";
    include("dbconfigfile.php");
    if ($_POST['d'] == "1") {
    foreach($_POST as $key => $val) {
    if ($key != "*.*" && $key != "*" && $key != "d") {
    // delete file name only from images-filename, but... if the imagelocation is empty then delete the whole entry line from DB.
    //delete file from folder if exists !
    unlink($uploaddir . $key);
    echo($uploaddir . $key."<br><br><br><br>");
    echo($key.' Deleted<br>');
    mysql_query("DELETE FROM `images` WHERE `filename` ='" . $key . "' LIMIT 1;") or die(mysql_error());
    }
    }
    echo("files are not really deleted yet, still working on it.");
    } else {
    ?><p align="center">Please note that if you upload a file with the same name as another file you have uploaded, this new file will over write the old file.</p><p align="center">Your Existig Files...</p><p align="center">
    <? $dh = opendir($uploaddir);
    ?><form name="form1" method="post" action=""><input name="d" type="hidden" value="1"><?
    while (false !== ($filename = readdir($dh))) {
    $ext = getFileExtension($filename);
    if(in_array($ext, $allowed)) {
    ?><input type="submit" name="<?=$filename;?>" value="DELETE"> <?=$filename;?><br><?
    }
    }
    ?></form></p>
    <form action="" method="POST" enctype="multipart/form-data">
    <table width="444" height="218" border="1" align="center">
    <tr align="center">
    <td height="152" colspan="2">
    <? if(isset($_REQUEST['submit']) && $_FILES['imgfile']['name'] != "") {
    $file = $_FILES['imgfile']['name']; $tmp_file = $_FILES['imgfile']['tmp_name']; $size = $_FILES['imgfile']['size'];
    $upload = $uploaddir . $file; $ext = getFileExtension($file);
    if(!in_array($ext, $allowed)) { echo "ERROR: Invalid file extension.";
    } elseif (move_uploaded_file($tmp_file, $upload)) {
    // set info about image in mysql
    $update = mysql_query("INSERT INTO `images` (`imagelocation` , `filename`, `uploadedby`) VALUES ('', '" . $file . "', '" . $_SESSION['adminusername'] . "')") or die(mysql_error());
    echo $file."<br>Upload successfully!<br>";
    } else { echo "Image upload failed.";
    }
    } else { echo("No file uploaded");
    } ?>
    </td>
    </tr>
    <tr><td height="28" colspan="2"><div align="right"><input type="file" name="imgfile"><input type="hidden" name="MAX_FILE_SIZE" value="20000"></div></td></tr>
    <tr><td width="372" height="28"><p>.doc .gif .jpg .wma .mp3 .pdf .ppt .pub .rtf .txt .zip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; only</p></td><td width="56"><input name="submit" type="submit" value="Upload"></td></tr>
    </table>
    </form>
    <? }
    } ?>

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Add a trailing slash to your $uploaddir.

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    after looking at code i noticed that i forgot to add this in the code i put here.

    i also looked at the source code of the page and noticed that the file name is correct, but when it is got using the $_POST it for some reason adds a _ in place of the .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •