<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>phpimage gallery Archives -</title>
	<atom:link href="https://mitindia.in/tag/phpimage-gallery/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/phpimage-gallery/</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2023 06:50:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>phpimage gallery Archives -</title>
	<link>https://mitindia.in/tag/phpimage-gallery/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Upload Image to server or database using php</title>
		<link>https://mitindia.in/image-gallery-using-php/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Fri, 06 Jan 2023 06:48:21 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP-MySQL]]></category>
		<category><![CDATA[image gallery]]></category>
		<category><![CDATA[image gallery using php]]></category>
		<category><![CDATA[phpimage gallery]]></category>
		<guid isPermaLink="false">https://www.mitindia.in/?p=1287</guid>

					<description><![CDATA[<p>Another interesting article on that how to insert or store an image or any file (pdf preferably) into a database or at server location. Let&#8217;s begin! First need to create an HTML File uploading image save file as upload.html &#60;hhtml&#62; &#60;head&#62; &#60;title&#62; Upload files to server &#60;/title&#62; &#60;style&#62; #tab{background-image: linear-gradient(to right, white, lightgreen); border: solid; [&#8230;]</p>
<p>The post <a href="https://mitindia.in/image-gallery-using-php/">Upload Image to server or database using php</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Another interesting article on that how to insert or store an image or any file (pdf preferably) into a database or at server location.</p>
<p>Let&#8217;s begin!</p>
<p>First need to create an HTML File uploading image</p>
<p>save file as upload.html</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;hhtml&gt;
&lt;head&gt;  

&lt;title&gt; Upload files to server &lt;/title&gt; 
&lt;style&gt; 
#tab{background-image: linear-gradient(to right, white, lightgreen); border: solid; border-color: darkorange; border-radius: 5px}


#hd{background-image: linear-gradient(to right, teal, lightgreen); border: solid; border-color: darkorange; border-radius: 5px; color: white; text-shadow: 2px 2px darkgreen; font-family: monospace;}


body{
    background-image: linear-gradient(to right, lightgreen, white); border: solid; border-color: darkorange; border-radius: 5px}
}


&lt;/style&gt;
&lt;/head&gt;  


    &lt;body&gt; &lt;center&gt;
        &lt;h1 id='hd'&gt; Upload Images to Server &lt;/h1&gt; &lt;hr&gt;
&lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
    Select Image File to Upload:
    &lt;input type="file" name="file"&gt;
    &lt;input type="submit" name="submit" value="Upload"&gt;
&lt;/form&gt;
&lt;br&gt;&lt;br&gt;
&lt;hr&gt;
&lt;a href="http://localhost/demo/imgdb/display.php"&gt; View Images &lt;/a&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Output looks as following</p>
<p><img decoding="async" class="alignnone size-medium wp-image-1288" src="http://www.mitindia.in/wp-content/uploads/2023/01/upload_1-300x120.png" alt="" width="300" height="120" srcset="https://mitindia.in/wp-content/uploads/2023/01/upload_1-300x120.png 300w, https://mitindia.in/wp-content/uploads/2023/01/upload_1-1024x411.png 1024w, https://mitindia.in/wp-content/uploads/2023/01/upload_1-768x308.png 768w, https://mitindia.in/wp-content/uploads/2023/01/upload_1.png 1283w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>Now, create a table in your existing or new database as following.</p>
<p><img decoding="async" class="alignnone size-medium wp-image-1289" src="http://www.mitindia.in/wp-content/uploads/2023/01/tab-300x109.png" alt="" width="300" height="109" srcset="https://mitindia.in/wp-content/uploads/2023/01/tab-300x109.png 300w, https://mitindia.in/wp-content/uploads/2023/01/tab-1024x371.png 1024w, https://mitindia.in/wp-content/uploads/2023/01/tab-768x278.png 768w, https://mitindia.in/wp-content/uploads/2023/01/tab.png 1337w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>Now create database configuration file called &#8220;db.php&#8221; as following code</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;?php
// Database configuration to connect mysql
$dbHost     = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName     = "college_db";
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
if ($db-&gt;connect_error) {
    die("Connection failed: " . $db-&gt;connect_error);
}
?&gt;</pre>
<p>Now create upload.php for uploading file to server</p>
<p>&nbsp;</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php">&lt;html&gt;
&lt;head&gt;  

&lt;title&gt; Upload files to server &lt;/title&gt; 
&lt;style&gt; 
#tab{background-image: linear-gradient(to right, white, lightgreen); border: solid; border-color: darkorange; border-radius: 5px}


#hd{background-image: linear-gradient(to right, teal, lightgreen); border: solid; border-color: darkorange; border-radius: 5px; color: white; text-shadow: 2px 2px darkgreen; font-family: monospace;}


body{
    background-image: linear-gradient(to right, lightgreen, white); border: solid; border-color: darkorange; border-radius: 5px}
}


&lt;/style&gt;
&lt;/head&gt;  

&lt;body&gt;

&lt;?php
// Include the database configuration file
include 'db.php';
$statusMsg = '';

// File upload path
$targetDir = "uploads/";
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(isset($_POST["submit"]) &amp;&amp; !empty($_FILES["file"]["name"])){
    // Allow certain file formats
    $allowTypes = array('jpg','png','jpeg','gif','pdf');
    if(in_array($fileType, $allowTypes)){
        // Upload file to server
        if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
            // Insert image file name into database
            $insert = $db-&gt;query("INSERT into images (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
            if($insert){
                $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
            }else{
                $statusMsg = "File upload failed, please try again.";
            } 
        }else{
            $statusMsg = "Sorry, there was an error uploading your file.";
        }
    }else{
        $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, &amp; PDF files are allowed to upload.';
    }
}else{
    $statusMsg = 'Please select a file to upload.';
}

// Display status message
echo $statusMsg;
?&gt;
&lt;/body&gt;

&lt;br&gt;&lt;br&gt;
&lt;hr&gt;
&lt;a href="http://localhost/demo/imgdb/display.php"&gt; View Images &lt;/a&gt;
&lt;/html&gt;</pre>
<p>&nbsp;</p>
<p>Output looks as following</p>
<p><img decoding="async" class="alignnone size-medium wp-image-1290" src="http://www.mitindia.in/wp-content/uploads/2023/01/upload2-300x79.png" alt="" width="300" height="79" srcset="https://mitindia.in/wp-content/uploads/2023/01/upload2-300x79.png 300w, https://mitindia.in/wp-content/uploads/2023/01/upload2-1024x270.png 1024w, https://mitindia.in/wp-content/uploads/2023/01/upload2-768x202.png 768w, https://mitindia.in/wp-content/uploads/2023/01/upload2-1210x324.png 1210w, https://mitindia.in/wp-content/uploads/2023/01/upload2.png 1229w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>&nbsp;</p>
<p>Note: also create &#8220;uploads&#8221; folder in your current working directory</p>
<p>Now, create display.php to view all images which you have uploaded.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php">&lt;html&gt;
&lt;head&gt;  
&lt;title&gt; Image Gallery &lt;/title&gt; 
&lt;style&gt; 
#tab{background-image: linear-gradient(to right, white, lightgreen); border: solid; border-color: darkorange; border-radius: 5px}


#hd{background-image: linear-gradient(to right, teal, lightgreen); border: solid; border-color: darkorange; border-radius: 5px; color: white; text-shadow: 2px 2px darkgreen; font-family: monospace;}

body{
    background-image: linear-gradient(to right, lightgreen, white); border: solid; border-color: darkorange; border-radius: 5px}
}

&lt;/style&gt;
&lt;/head&gt;  
&lt;body&gt;
&lt;center&gt;&lt;h1 id='hd'&gt; Image Gallery &lt;/h1&gt; &lt;hr&gt;
&lt;?php
// Include the database configuration file
include 'db.php';

// Get images from the database
$query = $db-&gt;query("SELECT * FROM images ORDER BY uploaded_on DESC");

if($query-&gt;num_rows &gt; 0){
    while($row = $query-&gt;fetch_assoc()){
        $imageURL = 'uploads/'.$row["file_name"];
?&gt;
    &lt;img src="&lt;?php echo $imageURL; ?&gt;" alt="" width="100" height="100"/&gt;
&lt;?php }
}else{ ?&gt;
    &lt;p&gt;No image(s) found...&lt;/p&gt;
&lt;?php } ?&gt;

&lt;br&gt;&lt;a href="http://localhost/demo/imgdb/upload.html"&gt;Back to Upload Images &lt;/a&gt;

&lt;/body&gt;&lt;/html&gt;</pre>
<p>&nbsp;</p>
<p>Finally, see the output of your gallery page of all images which are uploaded into server / database location.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1291" src="http://www.mitindia.in/wp-content/uploads/2023/01/display-300x127.png" alt="" width="300" height="127" srcset="https://mitindia.in/wp-content/uploads/2023/01/display-300x127.png 300w, https://mitindia.in/wp-content/uploads/2023/01/display-1024x432.png 1024w, https://mitindia.in/wp-content/uploads/2023/01/display-768x324.png 768w, https://mitindia.in/wp-content/uploads/2023/01/display.png 1294w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fimage-gallery-using-php%2F&amp;linkname=Upload%20Image%20to%20server%20or%20database%20using%20php" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fimage-gallery-using-php%2F&amp;linkname=Upload%20Image%20to%20server%20or%20database%20using%20php" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fimage-gallery-using-php%2F&#038;title=Upload%20Image%20to%20server%20or%20database%20using%20php" data-a2a-url="https://mitindia.in/image-gallery-using-php/" data-a2a-title="Upload Image to server or database using php"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/image-gallery-using-php/">Upload Image to server or database using php</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
