Jump to content

Recommended Posts

I want people to be able to post images on to my page but i want them to be able to add a caption when they post their image

This is the format I want the image and caption to be posted like

<div class="spacer"> </div>
	<div class="jokestary-img" title="Siri will screw up your relationship">
	<img src="uploads/Siri will screw up your relationship.jpg" />
	<div class="caption"><div>Siri will screw up your relationship.</div></div></div> 
                       

The code for the upload form also wont work

The page says "Upload complete!" before i even choose a file and doesnt send to my database

?php

// properties of the uploaded file
$name = $_FILES ["myfile"] ["name"];
$type = $_FILES ["myfile"] ["type"];
$size = $_FILES ["myfile"] ["size"];
$temp = $_FILES ["myfile"] ["tmp_name"];
$error= $_FILES ["myfile"] ["error"];

if ($error > 0)

	die ("Error uploading file! code $error.");
else
{
if ($type== "video/av/png || $size 1000000") //conditions for file
{
	die("That format is not allowed or file size too big");
}
else
	
	move_uploaded_file($temp,"uploads/".$name);	
	echo "Upload complete!";
}
?>

Simply save the path and name of file to a database table, along a text description of the image (which you would get from the user's input). Then when you can retrieve all the necessary information to do what you want it to do. That's the thought process that I would do, I  have done a picture gallery without the description portion, but it wouldn't be to hard to add that feature. For all I would have to do is add another column in my database structure. Anyways, throw in some JQuery (JavaScript) into the mix and you can really get some neat results. 

 

This is an example of what I do after I process my file upload then I proceed to save the info to a database table:

// Insert into the database using PDO and prepared statements:
$query = 'INSERT INTO pictures (thumbnail, picName, subDirectory, user_name) VALUES (:thumbnail, :picName, :subDirectory, :userName)';
$stmt = $pdo->prepare($query);
$result = $stmt->execute(array(':thumbnail' => $thumbImage, ':picName' => $image, ':subDirectory' => $name, ':userName' => 'Strider64'));

$resultDir = displayDir($pdo, $name); // Re-display the thumbnails:
Edited by Strider64
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.