Jump to content

Search the Community

Showing results for tags 'unlink'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. Hello Happy Campers. Wonder if someone can point me in the right direction if it's not too much trouble. I have a script that allows an EU to edit a database entry. The users edits the information and hits submit which then edits the content and it all works spiffingly. My problem however arises when I go to upload a new image. The "Add" function uploads images to a directory and the location is saved in the database. When editing the image however, it unlinks it but it does not allow me to upload a new image. The code is as follows: ini_set('display_errors',1); error_reporting(E_ALL); $conn = mysqli_connect("HOST","DB","PWRD","DBTBL") or die('Cannot Connect to the database'); $i = mysqli_real_escape_string($conn,$_POST['newsid']); $t = mysqli_real_escape_string($conn,$_POST['title']); $st = mysqli_real_escape_string($conn,$_POST['stat']); $sn = mysqli_real_escape_string($conn,$_POST['snip']); $s = mysqli_real_escape_string($conn,$_POST['stry']); $c = mysqli_real_escape_string($conn,$_POST['cap']); $f = $_POST['oldim']; $s = nl2br($s); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } else { $finame = $_FILES["file"]["name"]; $result = move_uploaded_file($_FILES['file']['tmp_name'], "../news/$finame"); if ($result == 1) { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsimage='$finame' newscaption='$c',newsstatus='$st' WHERE newsid=$i"; $d = "../news/"; unlink("$d$f"); } else { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } } } $result = mysqli_query($conn, $naquery); if($result){ header('Location: ../news.php'); } else { echo "Oh No! Something has gone wrong and the data could not be uploaded"; echo "<br />"; echo "click <a href='Link'>here</a> to return to News"; } mysqli_close($conn); I am not getting an error message from PHP, I am just getting the generic "Something has gone wrong" that I have coded in myself. Is there anyone who can point me in the right direction please? Cheers
  2. Hello I am new here, and so i am to php.. i have a small question - i think anyone here could help me, im sure :-) I have a php-gallery running locally on my desktop (using xampp), the gallery just shows images from a directory where a webcam saves its pictures in it (the gallery is named "ubergallery" - maybe anyone knows this gallery). Now i really would like to have following option: - A Button on the thumbnail called "delete" - when clicking on it, the picture should get replaced with another, predefined, placeholder-picture. I really hope somebody here can help me ! Thank you so much for your time ! I have attached the files! UberGallery.php index.php index.php
  3. Hey, I am trying to write some code that deletes all the files in a directory and then deletes the directory. The code below pretty much fetches a store ID from all the stores listed below, then it does a mysql fetch array on the store id to find it "store_name" which is the name of the directory, and then the next step is to delete the files and the whole directory. The reason why there is a foreach loop is because I would like to delete the files and folder for multiple stores at the same time. Below is the code. <?php require_once("include/database_connection.php"); global $connection;?> <?php if(isset($_POST['submit'])) { $store = $_POST['store_id']; // assign the store ID to the $store variable foreach ($store as $store_id) { // Run a foreach loop to get the store id $query = "SELECT * FROM stores WHERE store_id = {$store_id} "; // Run the query for the specific store id $result_query = mysql_query($query,$connection); // Execute the query $result = mysql_fetch_array($result_query,$connection); // Run a mysql fetch array on the result query $store_name = $result['store']; // get the store name $rmdir = rmdir("store/store_folders/".$store_name); // Delete the directory. if(!$rmdir) { echo $store_name ."Could not be deleted"; } //$query = "DELETE FROM store_names WHERE store_id = {$store_id} LIMIT 1"; //$result = mysql_query($query,$connection); //if($result) {echo "Store Deletion Successful";} } } ?> <form action="delete_stores.php" method="post"> <?php // Following code list all the stores with their checkboxes $count=1; $get_all_stores = "SELECT * FROM stores "; $query = mysql_query($get_all_stores, $connection); while($display_store = mysql_fetch_array($query)) { echo "<input type=\"checkbox\" value=\"{$display_store['store_id']}\" name=\"store_id[]\">" . $count . " " . $display_store['store_name'] . "</input>" ."<br>"; $count++;} ?> <input type="submit" name="submit" value="submit"> </form>
  4. I am using WAMP to run PHP code and MYSQL database So, I am working on a project that involves setting up a user with a profile picture. I was able to add a profile picture easily, but then as I realized I should implement a way to delete the old profile picture BEFORE changing to a new uploaded image by the user otherwise my directory will fill up with old pictures which is not what I want for a future application online with limited storage. Anyways, before I post my code, I must state that all of the folders involved have read and write permissions (no .htaccess involved). Here is the (delete_old_prof_img) function code : function delete_old_prof_img($user_id) { $old_path = mysql_query("SELECT `prof_img` FROM `users` WHERE `user_id` = " . (int)$user_id); // Find the old profile image if($old_path == "") // If it has nothing in the profile iamge column just return true { return true; } else if(unlink($old_path) == true && $old_path !== "") // If it is succesfully removed and the old path doesn't equal an empty string { mysql_query("UPDATE `users` SET `prof_img` = '' WHERE `old_prof_img` = '" . $old_path . "'"); // Reset the profile image column return true; } else // If image couldn't be removed just return false { return false; } } When I tried copying the $old_path into the mysql database into a column it returns "Resource id#14." The weirdest thing that I noticed was that the unlink function works fine if I put in the relative location such as unlink('images/profile/myimg.jpg') . Although, when I run the "delete_old_prof_img" function, the image in my directory is not removed, and it returns false. The database has the correct relative link to the location of the file in the 'prof_img'. Here is the page code it is used in. Please notice this is an nested conditional within others dealing with the html form. $allowed = array('jpg', 'jpeg', 'gif', 'png'); // Allowed extensions to be uploaded $file_name = $_FILES['prof_img']['name']; // File name of the image uploaded $file_extn = strtolower(end(explode('.', $file_name))); // File extension of the image uploaded $file_temp = $_FILES['prof_img']['tmp_name']; // The temporary file name if (in_array($file_extn, $allowed) === true) // If the file uploaded is in the list of those allowed to be uploaded, continue. { if(delete_old_prof_img($session_user_id) == true) // If the old image is deleted, continue. { change_prof_img($session_user_id, $file_temp, $file_extn); // Change the profile image to the newly uploaded one. header('Location: settings.php?upload_success'); // Return to a success page. exit(); // Exit } else if(delete_old_prof_img($session_user_id) == false) // If the old image cannot be deleted, continue. { header('Location: settings.php?upload_failure'); // Return to a failure page. exit(); // Exit } else // First time uploading { change_prof_img($session_user_id, $file_temp, $file_extn); // Change profile image header('Location: settings.php?upload_success'); // Return to success page. exit(); // Exit } } else { $errors[] = 'Incorrect file type. Allowed: ' . implode(', ', $allowed); // Put errors in the error array if not allowed file types, to be returned later. } I have turned on error reporting, but nothing has come up. Any redesign is appreciated, if this can be more simplified. Thank you for your time.
×
×
  • 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.