Jump to content


New Members
  • Posts

  • Joined

  • Last visited

Tahhan's Achievements


Newbie (1/5)



  1. I am trying to upload multiple images to the server and at the same time insert the images info into a MySql database. I am trying to achieve this using PHP OOP, I tried many ways using the foreach loop, but did not get any luck with it, any ideas on how can I solve this issue. PHP images class code: <?php class Images extends Crud{ protected static $db_table = "images"; protected static $table_fields = array("id", "image_url", "property_id", "date"); public $id; public $image_url; public $property_id; public $date; public $filename; public $tmp_path; public $upload_dir = "images"; public $errors = array(); public $upload_errors_array = array( UPLOAD_ERR_OK => "There is no error.", UPLOAD_ERR_INI_SIZE => "The file size exceeds the upload_max_filesize", UPLOAD_ERR_FORM_SIZE => "The file upload exceeds the MAX_FILE_SIZE", UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded", UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder", UPLOAD_ERR_CANT_WRITE => "Failed to write file on desk", UPLOAD_ERR_EXTENSION => "A PHP extension stopped the file upload" ); public function image_path(){ return $this->upload_dir.DS.$this->image_url; } public function set_files($file){ if(empty($file) || !$file || !is_array($file)){ $this->errors[] = "There was no file uploaded here"; return false; }else{ $this->image_url = $file['name']; $this->tmp_path = $file['tmp_name']; } } public function new_images(){ $this->set_files($_FILES['images']); $this->property_id = "1"; $this->date = date('Y-m-d H:i:s'); $target_path = $this->upload_dir . DS . $this->image_url; move_uploaded_file($this->tmp_path, $target_path); if($this->create()){ return true; } } } ?> HTML form: <?php include_once "admin/head.php"; ?> <?php if(!$session->is_signed_in()) {redirect("../index");} ?> <?php if(isset($_POST['submit'])){ $images = new Images(); $images->new_images(); } ?> <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-6"> <form class="form-horizontal" action="" method="post" enctype="multipart/form-data"> <div class="form-group"> <input type="file" class="form-control" name="images[]" id="images" multiple> </div> <input type="submit" name="submit" value="Submit" class="btn btn-primary"> </form> </div> </div> </div> <?php include "admin/footer.php"; ?> I want to be able to select more than 1 image at the same time, upload the images to the server, and insert each image info in a MySql database row. any help or advice would be appreciated.
  2. I had this issue in the past, I even hired an advanced PHP developer to solve it, and then it turned out that I was forgetting to implement it in the a tag.
  3. Thanks for the reply, I really appreciate it from you, pardon me please as I am not an advanced PHP user, especially when it comes to OOP and MVC, I have tried to do what you wrote me. but still having the same issue. I just want to know how to pass the variable which is id in the URL, without showing the "?" and "=" sign, I would really appreciate it if you help with this, as I have been trying for more than 3 days and couldn't achieve anything.
  4. I have followed a youtube playlist to build a simple MVC framework based on PHP, here is a link to the playlist I have followed. and here is an image of my application structure image I have connected the application to a MySql database, everything is working fine, but now I am trying to do friendly URLs. Currently, my URLs look like the following: mywebsite.com/public/home/property This is fine as this link is for a static page, but I want the same for dynamic URLs, for example: Current URL: mywebsite.com/public/home/property?id=10 to URL: mywebsite.com/public/home/property/id/10 I have tried a lot of methods in htaccss but the data is not pulled from the database once the URL is re-written and I get only an empty page. current .htaccess code (the one that is located in the public folder): Options -MultiViews RewriteEngine On RewriteBase /public RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] I have tried a lot of methods and rules but non have worked. I am not sure if the details I provided are clear enough, I am little confused as I combined a lot of tutorials together to create this app. App.php code: <?php class App{ protected $controller = 'home'; protected $method = 'index'; protected $params = []; public function __construct(){ $url = $this->parseUrl(); if(file_exists('../app/controllers/' . $url[0] . '.php')){ $this->controller = $url[0]; unset($url[0]); } require_once '../app/controllers/' .$this->controller. '.php'; $this->controller = new $this->controller; if(isset($url[1])){ if(method_exists($this->controller, $url[1])){ $this->method = $url[1]; unset($url[1]); } } $this->params = $url ? array_values($url) : []; call_user_func_array([$this->controller, $this->method], $this->params); } public function parseUrl(){ if(isset($_GET['url'])){ return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL)); echo $url; } } } ?> controller.php code: <?php class Controller{ public function model($model){ require_once '../app/models/' . $model . '.php'; return new $model(); } public function view($view, $data = []){ require_once '../app/views/' . $view . '.php'; } } ?> controllers code: <?php class home extends Controller{ public function index(){ $this->view('home/index'); } public function listings(){ $this->view('home/listings'); } public function property(){ $this->view('home/property'); } } ?> code for the page that should show data from mysql database: <?php include "includes/head.php"; ?> <?php $property = Property::find_id($_GET['id']); ?> <section id="sub-main"></section> <section id="sub-list"> <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-6"> <div id="listingCarousel" class="carousel slide" data-ride="carousel"> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=585%C3%97380&w=585&h=380" alt=""> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=585%C3%97380&w=585&h=380" alt=""> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=585%C3%97380&w=585&h=380" alt=""> </div> </div> </div> </div> <div class="col-xs-12 col-sm-6"> <h1><?php echo $property->property_name; ?></h1> <ul class="list-inline"> <li><i class="fa fa-map-signs" aria-hidden="true"></i> <b></b> <?php echo $property->city; ?></li> </ul> </div> </div> <hr> <div id="map"></div> </div> </section> <?php include "includes/subscribe.php"; ?> <?php include "includes/footer.php"; ?> The project is online, I can give full access if someone interested in helping me solve this issue.
  • 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.