PHP - Storing Pictures.
Hi, i would like to know what is the best method to store a picture. Currently what happens, is each user has a different avatar, which when uploaded comes in a folder called Avatar, in my website folder and is also stored as a BLOB in mysql. I would like to know is this ok to store all avatars in one folder or some other step should be used and if so could some one guide me to a good tutorial. As I would also like to make an option, where people could upload their pictures, is it safe to store pictures in the same folder for all users or some how create a different folder for each user.
Similar TutorialsHello. I'm working on a website with an editor that allows image uploading. Ideally I want to be able to develop a framework for this and use it in later projects. What I have in mind is this: Database has an images table Entries contain these fields: id, filename, and a short description Images are referred to by their ids in other parts of the application. That part seems simple to me, but now there are two details I need to determine: the file name, and storing the images. Big sites like Facebook - as far as I know - parse uploads and store them all in the same format. I can see the huge security benefit there. What are the best ways of doing that? As for the file name, I know PHP has a function to generate a file with a unique name. Is there any benefit to doing that over using the id? (i.e. 1.jpg, 2.png, 3.jpg, etc) try { echo "<br>"; foreach($dbh->query("SELECT * FROM test_shot WHERE sold=1 ORDER BY year ASC") as $row) { if($row['picture'] != "" && $row['picture'] != null) { echo "<div class='image-holder'><img src ='".$row['picture']."' width=300px /><br>"; } if($row['year'] != "" && $row['year'] != null) { echo $row['year']; } if($row['description'] != "" && $row['description'] != null) { echo $row['description']; } if($row['sold'] == 1) { echo "<img src='images/sold1.png'><br>";//Add your image code here } elseif ($row['sold'] == 0) { echo "</div><br>"; } } } catch (PDOException $e) { print $e->getMessage(); } ?>
if you have the urls to pictures in a database how would you display the actual pictures on a webpage? Here 's the code. Code: [Select] <?php require_once("functions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <?php navBar(); echo "<form action=\"\" method=\"post\" name=\"catalog\">"; DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $i = 0; echo "<table>"; while ($row = mysql_fetch_array($result_set)) { echo"<tr><td width=\"400px\">($row['product_pic']). <br />{$row['product_id']}.<br />{$row['product_title']}.<br /> {$row['product_Description']}.<br />{$row['product_price']}</td></tr>"; } echo "</table>"; ?> </form> </body> </html> Hello, like I promised, I'm back with another problem. This one will be harder xD so squeeze your brain
Now I've got a webpage, with a database shown into a table, under that I've got page numbers. So I got my 20 rows for each page.
https://www.dropbox..../stillnotok.jpg
Great/awesome so far
Now I've got a new problem and it's hard for me to explain this too.
In my database I got allot of tables, in my webpage I'm using 2 of them, called 'artikel' and 'images".
Everything from my artikel table is ok. So we don't need to look at that.
But my problem is with the table 'images'.
In that table I got 2 items.
Like you will see in my code, I need the I_ARTCODE and I_FILE
in I_ARTCODE stands: 14 and for the other image 15
in I_FILE stands: 5.jpg and for the other image 6.jpg
With the code I've got now, I display the word 5.jpg and 6.jpg.
But I need to display the picture behind that, the person who gave me this task sayed, I normally can do this with the pad but it's not a real url, I'll give you guys a picture how my database looks like:
https://www.dropbox....uqplxd/path.jpg
Over here the pad is this: 000000-001000
It doesn't seems normal to me and I can't find a sollution for this on the internet.
Can someone plz help me?
Ooh ya, almost forgot, this is my code:
<?php include('connect-mysql.php'); if (!empty($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 20; $sqlget = "SELECT * FROM artikel, images LIMIT $start_from, 20 "; $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting'); echo "<table>"; echo "<tr><th>A_ARTCODE</th><th>A_NUMMER</th><th>A_OMSCHRN</th><th>A_REFLEV</th><th>A_WINKEL</th><th>I_ARTCODE</th><th>I_FILE</th></tr>"; while($row = mysqli_fetch_array($sqldata)){ echo "<tr><td align='right'>"; echo $row['A_ARTCODE']; echo "</td><td align='left'>"; echo $row['A_NUMMER']; echo "</td><td align='left'>"; echo $row['A_OMSCHRN']; echo "</td><td align='left'>"; echo $row['A_REFLEV']; echo "</td><td align='right'>"; echo $row['A_WINKEL']; echo "</td><td align='right'>"; echo $row['I_ARTCODE']; echo "</td><td align='right'>"; echo $row['I_FILE']; //echo "<img src='000000-001000".$row['I_ID']."' />"; echo "</td></tr>"; } echo "</table>"; $sql = "SELECT COUNT(A_ARTCODE) FROM artikel"; $rs_result = mysqli_query($dbcon, $sql) or die ("mysqli query dies"); $row = mysqli_fetch_row($rs_result) or die ("mysqli fetch row dies"); $total_records = $row[0]; $total_pages = ceil($total_records / 20); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='index.php?page=".$i."'>".$i."</a> "; }; ?> Hi,
I have a crwal engine and every time when I try to take a picture from a specific website, it also take some bullshit from superfish, creating iframe and div class, that I can`t deleted using jquery after my page is load.
I was looking in my code and I found out that the only thing that trigger that is the <img src="<?php h(getPicture($itemRow['site'], if I remove 'site', I don`t see any other superfish code but also don`t see the picture. What can I do to take only the .jpg picture , without any of the other crap?
<?php for ($i = 0; $i < count($itemRow['pics']); $i++) { ?> Hi, I cant quite figure out how to assign an unique id to the picture I upload to my page, all help would be appreciated. Here's the upload code: //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; mysql_select_db("Database_Name") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> I need some help working through this. I have an uploader for files, but I'd like it to create a link of the file uploaded and automatically post it to a page. Each user has a profile page and I'd like these pictures to be posted to their profile page. I guess with a session, it would take the logged in username and post the pictures uploaded on the page " member_profile2.php?username=xxxx " Here is my upload file for reference. uploads.php Code: [Select] <?php $Dir = "temporary"; if (isset($_POST['upload'])) { //if file uploaded if (isset($_FILES['new_file'])) { //if successful if (move_uploaded_file($_FILES['new_file']['tmp_name'], $Dir . "/" . $_FILES['new_file']['name']) == TRUE){ chmod($Dir . "/" . $_FILES['new_file']['name'], 0644); echo "<b>File \"" . htmlentities($_FILES['new_file']['name']) ." was successfully uploaded </b><br />\n"; //displays file info echo "Name: ". htmlentities($_FILES['new_file']['name']) . "<br />". "Size: " . $_FILES['new_file']['size'] . " bytes" . "<br />". "Type: " . $_FILES['new_file']['type']; } //if not successful else { echo "<b>Uploading \"" . htmlentities($_FILES['new_file']['name']) . " was unsuccessful</b><br />\n"; } } } ?> <form action="uploads.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="250000" /><br /> Select file to upload:<br /> <input type="file" name="new_file" /> 250kB limit!<br /> <input type="submit" name="upload" value="Upload File" /><br /> </form> ?> and my member_profile2.php Code: [Select] <?php /*?><?php error_reporting(E_ALL ^ E_NOTICE); ?><?php */?> <?php # Starting the session session_start(); # Requiring SQL connection require_once 'mysql-connect2.php'; # Setting auser as SESSION['user'] $auser = $_SESSION['user']; # SQL protecting variables $username = (isset($_GET['username']))?mysql_real_escape_string($_GET['username']):$username; # Checking through each query if(isset($auser)) { $sql = mysql_query("SELECT * FROM `user` WHERE `username` = '$username'"); if(mysql_num_rows($sql)) { while($row = mysql_fetch_array($sql)) { $page = "<h1>User Info</h1>". "<b>Username: {$row['username']}<br /><br />". "<b>First Name: {$row['firstname']}<br /><br />". "<b>Last Name: {$row['lastname']}<br /><br />". "<b>Email: {$row['email']}<br /><br />". "<form name=\"backlistfrm\" method=\"post\" action=\"members2.php\">". " <input type=\"submit\" value=\"Back to The List\">". "</form><br />"; } } else { $page = "ERROR: No member found for username: <strong>{$_GET['username']}</strong>."; } } else { $page = "ERROR: Not logged in."; } # Printing the final output print $page; ?> I'd like the pictures to be displayed after the user details. Any help with this would be great. I was also thinking, could I just have the uploader save it as a filename with the user's username? For example, "user1-image1.jpg". And then have their profile page pull and display any files with the name user1-image1-10.jpg (10 being max possible uploads for that user). How would I do this? This sounds maybe easier. Hello there, I am working on a pagination script and have hit a bit of a wall. Here is the script: Code: [Select] <?php include("header.php"); ?> <?php $host = "localhost"; // $user = ""; //username to connect to database $pass = ""; //password to connect to database $db = ""; //the name of the database mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error()); mysql_select_db($db) or die("ERROR DB:".mysql_error()); $max = 25; //amount of articles per page. $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM 3dpics WHERE id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['title']; $url = $r['url']; echo "<div align='center'><img src='$url' width='500' height='500'><br />$title<br /><br /><a href='test.php'>Back</a></div>"; } }else{ //view all the articles in rows $sql = mysql_query("SELECT * FROM 3dpics LIMIT ".$limits.",$max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM 3dpics"),0); $totalpages = ceil($totalres / $max); echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo "<a href='test.php?p=$i'>$i</a>|"; } } ?> All this does is pull the url's of the images out of the database. But, it all shows up on 1 line across the screen! I tried echoing the rows instead, but then it just shows up as 1 line going horizontal. So i'm trying to figure out a way to get 5 pictures per row. This is the code that displays them on the main page: Code: [Select] echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table Thanks for all your help! I want to display pictures in a table using a PHP loop or something, for example 3 pictures in one row, and then when that row has filled, move to the next row, So I can have a grid of pictures, (similar to that on facebook, when your viewing photo albums)... But I've no idea how to do it! I am working on this pictures to upload and when I submit it gives the message below for success but I get this error message which is on the line of $place file Warning: move_uploaded_file(members/5/image01.jpg) [function.move-uploaded-file]: failed to open stream: $check_pic = "members/$id/image01.jpg"; $default_pic = "members/0/image01.jpg"; $newname = "image01.jpg"; $place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/".$newname); $success_msg = '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please be patient.</font>'; Hi guys, A beginner at php/mysql here... For a project I'm doing, I would like to display search results with an image, small description, then a 'read more' link. After googling this issue, I can't find much information on it, which surprised me. Someone did mention blobs for images... (whatever they are!) I'm wondering if anyone knows of any tutorials, or has any code to do this? Your help is much appreciated. Thanks. How would I write PHP code to echo the number of pictures I have in a folder on my hosting account?
Thanks in advance.
Hi there, Can you guys/girls tell me if this is even possible: - take pictures with eye-fi card in the camera, which uploads the images to a server - on the server, automatically add a watermark, and post them on 3 different facebookpages Hi all, I have a code which works just fine for adding one picture to my database but when I change the form to add mutliples i get an error because my code is set for multiple pictures as an array. Error says this is a string code. Does anyone know the code for array? Code: [Select] $target = "upload/"; $target = $target . basename( $_FILES['photo']['name']); Error message says Warning: basename() expects parameter 1 to be string, array given in /home/content/19/6550319/html/listingsss.php on line 7 Thanks, Philip Hi I am trying to create a dynamic gallery in php with specific order of pictures on the page, but I can't find the function or piece of php code to do so.
Conditions: My code: $files = glob("layout/gallery/*.jpg"); rsort($files, SORT_NATURAL); for ($i=0; $i < count($files); $i++) { for( ; $i<5; $i++){ $one = $files[$i]; echo '<img src="'.$one.'">' . '<br><br>'; } echo "<br>"; for( ; $i<9; $i++){ $two = $files[$i]; echo '<img src="'.$two.'">' . '<br><br>'; } } The code works well, but it just displays 9 pictures obviously. I was unable to make it dynamic displaying 5 pictures first, 4 pictures after and stay this way in a loop till displays all pictures from that folder. Hi everyone! I'm trying to create a form with an upload photo bit in it. The photo i know, has to be saved on the server somewhere. Iv'e created an images folder both in my host's control pannel and in my dreamwever files and FTP'd it to the server. I've tried both ways of sending the test .jpg to each folder but i'm getting the desgined mySQL error. What's going worng here? Code: [Select] <?php //This is the directory where images will be saved $target = "/images/COMPANIES"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['photo']['name']); // Connects to your Database mysql_connect("******host", "****username", "****password") or die(mysql_error()) ; mysql_select_db("****DB") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Thanks Hi, You may noticed that i've posted before and closed them. It was too hard. I've been searching around for something else and i found it. But it's not quite perfect. What i want to do is make thumbnails smaller (i can do that on my own) but displaying the bigger picture above the thumbnails. And aligning the thumbnails next to each other. So how do i do that? The current code: <?php $result = mysql_query("SELECT reference FROM user_photos WHERE`profile_id`='".$row['id']."'"); while ($row2 = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"".$_GET['username']."/pics/".$row2['reference']."\"> <img src=\"".$_GET['username']."/pics/thumbs/".$row2['reference']."\"></a><br/><br/>"; } } ?> The files are refering to the mysql in reference but are actually in a subfolder with the username on the server. I hope somebody wants to help me, Best regards, Martijn (the netherlands) Hello everyone, I'm new here
My website was working fine until a few days ago, Up until then my str_replace('s130x130', 's800x800') and str_replace('_s', '_o') solved the picture thing. Now the images are broken (or very small) and I can find no documentation on how to enlarge the pictures. Thus my question: how do I retrieve larger pictures from the Facebook PHP SDK?
Code
foreach($pagefeed['data'] as $post) { if ($post['type'] == 'status' || $post['type'] == 'link' || $post['type'] == 'photo') { if ($post['type'] == 'photo') { echo "<div class='col-md-6 col-sm-6'>"; echo "<div class='thumbnail'>"; echo "<img src=" . str_replace('s130x130', 's800x800', str_replace('_s', '_o', $post['picture'])) . " />"; echo "<div class='caption'>"; echo "<sup>Geplaatst op: " . date("d-m-Y, (strtotime($post['created_time']))) . "</sup>"; if (empty($post['message']) === false) { echo "<p><span class='glyphicon glyphicon-comment'></span> " . $post['message'] . "</p>";} echo "</div>"; echo "</div>"; echo "</div>"; $i++; } } }Thanks in advance! I am looking for help on guiding me to a way for a user to upload a group of pictures for a slide show. can some one help? I have a news page that a user is able to upload new stories or edit and upload one photo, but now i want that user to upload a group of pictures for a slideshow. hope all this makes sense. |