PHP - Submit Images To Diferent Folder In One Form
Similar TutorialsI have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
Hi, I want to be able to click on the photo and go to the next one in a folder. I have this code already, I just am not quite sure how to finish it. -George Code: [Select] <?php $count = $_GET['count']; $dir = "images"; $names = array(); $handle = opendir($dir); while ($name = readdir($handle)){ if(is_dir("$dir/$name")) { if($name != '.' && $name != '..') { echo "directory: $name\n"; } } elseif ($name != '.DS_Store' ) { $names[] = $name; } } closedir($handle); $numberofitems = count($names); $numberofitems--; if ($count <= $numberofitems){ echo "<p>"; echo "<img src='images/".$names[$count]."'>"; } else {echo "end";} ?> I made an upload image system, the images are stored in a folder, while the image name is stored in database. When I try to execute the image name, it works successfully, but when I try to disply the image from the folder by using the image name in the database, I fail each time. The folder where the images are being stored is named: saveimage Here is the query: Code: [Select] <?php mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('imagedatabase'); $images = mysql_query("SELECT * FROM img WHERE email='$lemail'"); while($row = mysql_fetch_array($images)) { echo "<img src='saveimage/'".$row['img_description']; } ?> The problem: I'm trying to create a page which outputs images from a folder which I have been able to do, but the problem I'm having is not being able to get the page to display the most recent image according to file modification date at the top. The first set of code below outputs the image timestamps in descending order, from newest to oldest which is what I want, but as soon as I change/add a couple lines of code (Shown in the second lot of code) to get the image file name along with the timestamp, the echoed list (timestamp and file names) gets muddled up in a random order. In short; As soon as the file names are retrieved with the timestamp, the list goes from being organised descendingly, to not. Show timestamp only code (1st lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = $filetime; } rsort($sortedimages); foreach ($sortedimages as $sorted) { //foreach ($sorted as $key => $value) //{ echo "$sorted<br/>"; } //} closedir($dir); ?> The show timestamp and file name code (2nd lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = array($filetime => $image); } rsort($sortedimages); foreach ($sortedimages as $sorted) { foreach ($sorted as $key => $value) { echo "$key and $value<br/>"; } } closedir($dir); ?> The changes made in the 2nd script from the 1st: //Changed: $sortedimages[] = $filetime; ---> $sortedimages[] = array($filetime => $image); //Included the previously commented out: foreach ($sorted as $key => $value) { } //Changed: echo "$sorted<br/>"; ---> echo "$key and $value<br/>"; Thanks for any help! I'm trying to write code that will let me pull 10 out of 15 images out of a folder and display them on my site. The images are all different, and I don't want dupes to show. So far, I have the following code figured out: --------------- $s = array ("image.jpg", "image2.jpg"); // as many images as you want $n = rand(1,len($s)); // randomly pick a number between 1 and the length of the array echo "<img src='". $s[$n] .'">"; // create an image tag for the randomly selected imagine (value of the randomly defined key) array_pop($s, $n); // This piece isn't right, it needs to EXTRACT and delete the $n array element. // Next random image $n = rand(1,len($s)); echo "<img src='". $s[$n] .'">"; --------------- Any ideas what array_pop should be to work properly? Thank you for the help! Can someone tell me how I can remove or delete an image from a folder on a server using PHP? I tried this: Code: [Select] unlink("http://midwestcreativeconsulting.com/jhrevell/wp-content/themes/twentyten_3/upload/" . $location); before my delete MySQL statement, but I keep getting this error: Warning: unlink() [function.unlink]: http does not allow unlinking in /home/midwestc/public_html/jhrevell/wp-content/themes/twentyten_3/removejewelry.php on line 22 Can anyone help and tell me how I can make it work? I have searched around and found this code that suggests that I should be able to read an image file and echo it directly in to the page without hyperlinking to the file that is outside the public folder, but i get the error message that it is not there even though the file is. Warning: getimagesize() [function.getimagesize]: Unable to access "/home/****/upload/AAABBBCCC.JPG" in /home/****/public_html/client.php on line 40 Code: [Select] $image = "AAABBBCCC.JPG"; $path= "/home/****/upload/"; $details = getimagesize($path . $image); header ('Content-Type: ' . $details['mime']); echo file_get_contents($path . $image); Im using this code to call all the images in a folder: Code: [Select] $handle = opendir(dirname(realpath(__FILE__)).'/images/'); while($file = readdir($handle)){ if($file !== '.' && $file !== '..'){ echo '<img src="admin/img/uploads/'.$file.'" border="0" />'; } } My html says the images are present but they aren't visable on screen: Code: [Select] <div id="contentbody"> <img src="admin/img/uploads/send-button-sprite copy.png" border="0" /> <img src="admin/img/uploads/test" border="0" /> <img src="admin/img/uploads/counter.jpg" border="0" /> <img src="admin/img/uploads/send-button-sprite.png" border="0" /> </div> Any help is much appreciated! Hi
I echo out images from a folder. The problem is that I have a html file in the same folder but I don't want to echo that out. How can I write my code to get rid of the html in the output?
Here my code:
<?php $filetype = '*.html'; $dirname = substr('$filetype'); $i=0; if (isset($_POST['submit2'])) { //get the dir from POST $selected_dir = $_POST['myDirs']; //now get the files from within the selected dir and echo them to the screen foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*') as $dirname) { echo substr($dirname, 0, -4); echo '<img src="'.$dirname.'" />'; echo "<label><div class=\"radiobt\"><input type='radio' name='radio1' value='$i'/></div></label>"; } } ?>P.S. when I echo out : substr($dirname, 0, -4); I want to get ride of the html filename there too. How can I do so something like this? Hello once again, i got this code that takes all images from a folder and displays them close to each other. Heres the code: <?php $dir = 'uploads/thumbs/watermarkedthumbs/'; $file_display = array ('jpg', 'jpeg', 'png', 'gif'); if (file_exists($dir) == false) { echo 'tt'; } else { $dir_contents = scandir($dir); foreach ($dir_contents as $file) { $file_type = strtolower(end(explode('.', $file))); if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) { echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />'; } } } ?> How do i add margins in between them? i wanna make it smth like 'margin-left:10px, margin-top-10px'. Also, how do i add an 'overflow'? i mean, my images currently are displayed in a div, and i wanna make it so that if the folder has lets say 9 images, it would only display 6 of them, and the rest would be displayed in the same div after i click a button or smth (like '1' for the first div and '2' would appear if theres an overflow, and when i click '2' the rest of the images would appear). To make these adjustments do i need to make a different php file or do i change something in this code? thanks in advance. Hey guys, i'm new to this site and would need some help with coding. So i'm making a car part website which should has brand/model search. It's a dropdown search which will get the brand / model from database and should display all the parts for that exact model, from folder. Database structure which i have is id, master, name. ( Here's some pictures to clear out what i'm doing. http://imgur.com/a/7XwVd ) So the problem is that it does not get the images from folder named ex: *_audi_a3.jpg. And link to codes what have been written already. Parts.php: http://pastebin.com/q6vdypge Update.php: http://pastebin.com/DymhGQ17 Search_images.php: http://pastebin.com/LF5Q0i8f Core.js: http://pastebin.com/bgc0y4TS I don't know what's wrong with it sadly. One thing i noticed when i used firebug it gives error on category when searching error:true. Hope you guys understand what i mean here, and also all help is appreciated. And move this post if it's in wrong place. Thanks! Edited by aeonius, 17 October 2014 - 12:15 PM. Basically i have a folder with 100+ images they are NOT all the same extension, what im wanting to do is use PHP to find all the images and put them all in a database. how would i go about doing this? thanks Say I have an "Entries" table. I want to submit same multiple entries using a form submission. And If I have other queries submitted in the same form, I want those quarries to be submitted only once. Is that possible to do? Here's my code. if(isset($_POST['submit'])) { $entries = 10; $id = 55; $name = 'Smith'; $insert = $db->prepare("INSERT INTO entries(id, name) VALUES(:id, :name)"); $insert->bindParam(':id', $id); $insert->bindParam(':name', $name); $result_insert = $insert->execute(); if($result_insert == false) { echo 'Fail'; } else { echo 'Success'; } } ?> <form action="" method="post"> <input type="submit" name="submit" value="SUBMIT" /> </form> Edited January 13, 2019 by imgrooot Hi. Pretty straight forward I guess but as the name suggests am a newbie. I have a form that requires the user to enter certain parameters. If the values are blank it submits to itself and loads the error messages. What I want to do is create PHP code that submits the form to a different url. What I thought was create two forms (the second with hidden fields replicating the first form), each form having a different url in the action"" code. What I cant work out is the PHP IF ELSE code to submit form 2 if Form1 is is validated correctly. This is the PHP code relevant to the form validation. Help? <?php //If form was submitted if ($_POST['submitted']==1) { $errormsg = ""; //Initialize errors if ($_POST[width]){ $title = $_POST[width]; //If title was entered } else{ $errormsg = "Please enter width"; } if ($_POST[drop]){ $textentry = $_POST[drop]; //If comment was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . " & content"; }else{ $errormsg = "Please enter drop"; } } } if ($errormsg){ //If any errors display them echo "<div class=\"box red\">$errormsg</div>"; } //If all fields present if ($title && $textentry){ //Do something echo 'THIS IS WHERE I WANT THE CODE TO SUBMIT FORM 2 or SUBMIT FORM 1 TO A DIFFERENT URL'; } ?> Any ideas on how to extract text from html like this into multiple variables? Code: [Select] <li class="even" style="padding-top:1.25em"><label for="job_title">Title</label><div>Expatriate Tax Director</div></li> <li class="odd"><label for="job_contract_type">Contract type</label><div>Permanent</div></li> <li class="even"><label for="job_market_sector">Market sector</label><div><a href="/en/candidate/market_sectors/1.html">Accountancy / Auditing / Tax</a></div></li> <li class="odd"><label for="job_country">Country</label><div><a href="/en/candidate/countries/GB.html">United Kingdom <img src='/images/flags/GB.png'/></a></div></li> <li class="even"><label for="job_location">Location</label><div>Reading</div></li> <li class="odd"><label for="job_min_salary">Salary</label><div>120.00 - 120.00 United Kingdom Pounds/Month <li class="even"><label for="job_description">Description</label><div>Expat Tax Director <br/>Circa 120k - UK - Reading <br/> <br/>Our client is seeking experienced tax professional to undertake this central role. This position has evolved due to the firm expanding. The firm now has an immediate need for a very experienced person to direct the team. The ideal individual will have experience in advising International organisations with international tax, cost & risk assessment as well as reorganisations of processes and systems for the management of cross border employees. Business Development skills and good Client Management are essential. <br/>Attractions: <br/>- Combination of HNWI, Corporate Expat Programmes and International Partnerships <br/>- Managing a skilled and established team <br/>- Working within a successful and profitable office <br/>- Central London location <br/></div></li> <li class="odd"><label for="job_expires_on">Expires on</label><div>February 28, 2013</div></li> <li class="even"><label for="job_ideal_candidate">Ideal candidate</label><div>Expatriate Tax</div></li> </ul></div></div><div class="warning">An EU passport or work permit is required for this position. Applicants without one of these will be rejected automatically.</div> Hi, how to let php read the url in folder form instead of querystring? e.g. www.example.com/index.php?post=123 www.example.com/post/123/ both is actually directed to the same page - index.php, but how to make it read like a folder when the physical path doesn't really exist? hello phpfreaks! first off i have zero knowledge of php. it's just that i need this in my project. what i would want to do is all the values input in the form "tracker.html" when the SUBMIT button is clicked will be saved in my desktop folder named "LOGS". the saved values will be save as an html file name "logs.html" then it can be viewed also by clicking on the PREVIEW button in the tracker. and also if can be done, each will be save separately according to it's CATEGORY. Code: [Select] <!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> </head> <body> <form id="form1" name="form1" method="post" action=""> <div> <label for="name3">Name: </label> <input type="text" name="name" id="name3" /> </div> <div> <label for="phone">Phone Number</label> <input type="text" name="phone" id="phone" /> </div> <div> <label for="ticket">Ticket Number</label> <input type="text" name="ticket" id="ticket" /> </div> <div> <label for="issue">Issue:</label> <select name="issue" id="issue"> <option value="no sync">no sync</option> <option value="no route">no route</option> <option value="resched">resched</option> <option value="cancel">cancel</option> </select> </div> <div> <label for="category">Category:</label> <select name="category" id="category"> <option value="level 1">level 1</option> <option value="level 2">level 2</option> <option value="level 3">level 3</option> </select> </div> <div><input type="file" name="upload" id="upload" /> </div> <div> <label for="summary">Summary:</label> <textarea name="summary" id="summary" cols="45" rows="5"></textarea> </div> <div> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="submit" name="preview" id="preview" value="Review" /> <input type="submit" name="clear" id="clear" value="Clear" /> </div> </form> </body> </html> <?php shell_exe ("172.18.9.25\photoshop\photoshop.exe"); ?> When I run this from the server computer program opening. But when i tried from a diferent computer it is only downloading the exe file to the client computer. How can I open the application from a diferent computer in the same network. I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; |