Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:20:45+00:00 2026-06-16T16:20:45+00:00

Im doing an image gallery CMS using Mysql database and PHP. Im a newbie.

  • 0

Im doing an image gallery CMS using Mysql database and PHP. Im a newbie.

Im having a path problem.

here is my file structure:
this php doc – root/php/upload_portrait.php.
My images are stored here – root/images/portrait_gallery/

So I added the ../ to save the images in root/images/portrait_gallery/
that works fine.

but in the db the url is stored with the ../ and that path is incorrect since they are being called from the root index file. So no images show up.

HOW can I remove the ../ upon INSERT INTO in the database??

I have tried with replace and update but cant figure out how.

Here Is my code

$portrait_url= $_FILES['upload'];

// 2. connect to database: 
include 'connect.php';

// 4. handle moving image from temp location to images folder (using the function billedupload)
$billedurl = billedupload($portrait_url);       
if($billedurl == false){        
    die("Something is wrong");
}

// 5. Insert imageupload in database:
$query = "INSERT INTO portrait (portrait_id, portrait_url) VALUES ('$portrait_id', '$billedurl')";
$result = mysqli_query($dblink, $query) or die( "Forespørgsel 2 kunne ikke udføres: " . mysqli_error($dblink) );

// 6. close connection
mysqli_close($dblink);

function billedupload($filearray){      
    if($filearray['type']=='image/jpeg' or $filearray['type']=='image/png'){
        $tmp_navn = $filearray['tmp_name'];             
        $filnavn = $filearray['name'];          
        $url = '../images/portrait_gallery/' . time() . $filnavn;           
        move_uploaded_file($tmp_navn, $url);            
    return $url;    
    } 
    else{           
        return false;       
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:20:46+00:00Added an answer on June 16, 2026 at 4:20 pm

    If all you need to to remove ‘/..’ — then,

    str_replace is a function in PHP that allows you to remove/change parts of strings on the fly, so, in your code,

    replace

    $billedurl = billedupload($portrait_url);

    with

    $billedurl = str_replace('/..','',billedupload($portrait_url));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an image gallery viewer, with little thumbnails, one medium-sized viewer, and
I've been doing research on image file upload security for a while but can't
I'm currently trying to teach myself PHP by doing a small image-processing type project
I am deleting an image file from my application. I was doing new File(filename).delete
I'm using the Forge file module to try and upload an image from the
Let´s say I have two PHP classes one called gallery and one called image
I'm having trouble to integrate the Galleria image gallery plugin onto one of my
I'm using the PrettyPhoto jQuery plugin for an image gallery, and I'd like to
I'm doing photo gallery and like to enlarge an image when I click on
I'm working on an image gallery at the moment and its doing something very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.