Metoriium Posted October 26, 2014 Share Posted October 26, 2014 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!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/292080-how-do-i-allow-users-to-upload-images-with-caption/ Share on other sites More sharing options...
Metoriium Posted October 27, 2014 Author Share Posted October 27, 2014 Can anyone solve this? Quote Link to comment https://forums.phpfreaks.com/topic/292080-how-do-i-allow-users-to-upload-images-with-caption/#findComment-1494905 Share on other sites More sharing options...
tryingtolearn Posted October 27, 2014 Share Posted October 27, 2014 is that the complete upload script you are using? Quote Link to comment https://forums.phpfreaks.com/topic/292080-how-do-i-allow-users-to-upload-images-with-caption/#findComment-1494909 Share on other sites More sharing options...
Strider64 Posted October 27, 2014 Share Posted October 27, 2014 (edited) 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 October 27, 2014 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/292080-how-do-i-allow-users-to-upload-images-with-caption/#findComment-1494910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.