Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php Image uploader

Featured Replies

Hi all

 

Need help with an image uploader to display portfolio images.

 

Here is what is happening at the moment:

 

What I want is for the images to be displayed on the portfolio page. I am using an uploads folder & want the image path to be stored in the db instead of storing the actual image in the db.

 

The php script above the html declaration on uploader.php:

 

//Start the session so we have access to stored data

session_start();

// Define variables

$image_title = "image_title";

$image_path = "image_path";

$username = "******";

$password = "************";

$localhost = "localhost";

$database = "*************";

 

// Check if the value has been inserted

if(isset($_POST['image_path']))

$_SESSION['image_path'] = $_POST['image_path'];

if(isset($_POST['image_title']))

$_SESSION['image_title'] = $_POST['image_title'];

 

// Connect to database

mysql_connect($localhost,$username,$password);

mysql_select_db($database) or die( "Unable to select database");

mysql_close();

?>

 

The form on the uploader.php page to upload the images from the admin section:

 

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">

<label for="image_title"></label>

<input type="text" name="image_title" id="image_title" /><br /><br />

<label for="image_path"></label>

<input type="file" name="image_path" id="image_path" />

<input type="submit" name="upload" id="upload" value="Submit" />

<input type="hidden" name="MM_insert" value="form1" />

</form>

 

 

What happens after is it doesn't go through at all or go into the uploads folder I created, neither does it show on the admin page where I will be able to delete the posts I have made.I get this message

 

Notice: Undefined index: image_path in C:\wamp\www\ca-design\admin\uploader.php on line 42

Call Stack

# Time Memory Function Location

1 0.0008 400784 {main}( ) ..\uploader.php:0

Column 'image_path' cannot be null

 

Can someone help me to see the error here. Still new in php Thanks

  • Author

I also have an upload-file.php script that I tried using. When I start the upload process it says that I have an undefined index on line 23 (Notice: Undefined index: uploadfile in C:\wamp\www\ca-design\admin\upload-file.php on line 23). Why could it be telling me this?

 

The upload-file.php script:

 

 

<?php

// Start the session

session_start();

 

// Define variables

$image_title = "image_title";

$image_path = "image_path";

$username = "*****";

$password = "**********";

$localhost = "localhost";

$database = "**************";

 

// Check if the value has been inserted

//if(isset($_POST['image_title']))

//$_SESSION['image_title'] = $_POST['image_title'];

//if(isset($_POST['image_path']))

//$_SESSION['image_path'] = $_POST['image_path'];

 

// Connect to database

mysql_connect($localhost,$username,$password);

mysql_select_db($database) or die( "Unable to select database");

$uploaddir = './uploads/';

$file = $uploaddir . basename($_FILES['uploadfile']['name']);

$max_file_size = 20000000 ;

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {

echo "success";

 

// Create a query to insert data

$query = mysql_query ("INSERT INTO images ('image_title','image_path') VALUES ('$image_title','$image_path')");

} else {

echo "Uploading of files failed";

}

mysql_close();

?>

 

This upload-file.php script I put here & took away the <?php echo $editFormAction; ?> part :

 

<form action="upload-file.php" method="POST" enctype="multipart/form-data" name="form1" id="form1">

<label for="image_title"></label>

<input type="text" name="image_title" id="image_title" /><br /><br />

<label for="image_path"></label>

<input type="file" name="image_path" id="image_path" />

<input type="submit" name="upload" id="upload" value="Submit" />

<input type="hidden" name="MM_insert" value="form1" />

</form>

 

Cant see the error Please assist thanks

Edited by Gemini12

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.