PHP - Need An Option To Take Photo From Website
Hai
i got a site where i take the details of the visitors that enter my office premises. Now what i wanted is to add the photo of the visitor into that. i have a webcam with me through which i can take pictures. I dont have an idea how to do this on the website. I need some one to help me on this.. I dont know really where to start.. Any help would be greately appreciatd.. Similar TutorialsFor the last 2 months I have purchased software and utilized free software to attempt to create a sitemap fro my websites
www.negroartist.com
www.africanafrican.com
all of them fail and do not look at all links. i.e. look at a photo album with all the htm in the photo album.
Most of the windows based software do not work and often crash. I want it to index ALL of my site (except images, pdf etc)
Is there any php code, program etc. out there to help me through my dilemna that has instructions for configurabillity? I can also try anything that uses apache etc.
i am at my whits end with this. please help.
has anyone used bing sitemap plugin? how do you install this baby?
my links will total in the hundreds of thousands.
thanks :-)
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=307346.0 I'm having a problem understanding how to import more than one photo in a list of up to 20 photos. I can only import 1 photo from a comma delimited csv with a pipe between each photo url. <? function getImg($value,$userid, $stocknum){ $photoStr = ''; if($value !=''){ $photoURLs = explode('|', $value); for($i=0; $i<count($photoURLs);$i++){ $url = $photoURLs[$i]; $j = $i+1; if (@copy($url, "../upload/".$userid."/".$userid."_".$stocknum."_".$j.".jpg")) { $photoStr .= $userid."_".$stocknum."_".$j.".jpg|"; } } } return $photoStr; } ?> And after csv and sql <? if($img){ $img = rtrim($img, '|'); $imgArray = explode('|', $img); $imgIndex = 1; foreach ($imgArray AS $imgItem){ $db->query("UPDATE `stockitem` SET img".$imgIndex."= '$imgItem' where stocknum='$stocknum'","" , __FILE__, __LINE__); $imgIndex++; } } ?> Any help would be appreciated. i am in the process of creating an auction site. However the images do not show , just the placeholder. Can anyone indicate where I have gone wrong ?
i am using this script to enter the items into the Database
html>
<link rel="stylesheet" type="text/css" href="style.css">
if(isset($_GET["item"]))
if($_GET["item"]=="duplicate")
else if($_GET["item"]=="successful")
}
echo "<label for='item_name' class='label'>Item Name:</label>";
echo "</form>";
</body>
This script displays the items :
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body> session_start();
if(!isset($_SESSION["username"]))
else
$DBHOST = "localhost";
while($row = $result->fetch_assoc())
$iid = $row["item_id"];
$conn->close();
Hi all, i was wondering if someone could point me in the right direction on how to create the following. After someone uploaded a photo than Cut out only his head in a fixed square say 90x120 pix (of a larger picture). I have seen some on the internet but most of them use flash and i rather use javascript or no javascript at all. Can this be done with GD library for instance where you just give the coordinates and the size of a square. (if this can be done automated i love to hear it) I have seen one where someone should pinpoint the eyes. IF someone has experience with this or a general idea on what techniques to use let me know I bet there are loads of way to do this but the most light weight technique would be great. Something like the attached image I let my members to upload their photos, I m using the script I coded which checks the file extension, if the file extension is "jpg" ( if ($this->url['type'] == "image/jpg")) and less than 600kb it uploads. Otherwise it gives you a warning.. What I wonder is, do I face any unwanted results about this later ? Like someone uploads a virus or script then execute it and do something ? Hey guys, I am a newb but trying to figure out how I can upload multiple associated photo files. My code is working for one photo, however I would like to have multiple photos that are associated uploaded at the same time. I would like the photos save in a format such as: photo_filename1 = 100, photo_filename2 = 100_a I am using the following code with no luck, not sure how I can work this. Any help is much appreciated!!! Thanks in advance. <code> <?php include("config.inc.php"); // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php $photos_uploaded1 = $_FILES['photo_filename1']; $photos_uploaded2 = $_FILES['photo_filename2']; // Fetch the photo caption array $photo_caption = $_POST['photo_caption']; while( $counter <= count($photos_uploaded1) ) { if($photos_uploaded1['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded1['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos(`photo_filename1`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ); $new_id = mysql_insert_id(); $filetype = $photos_uploaded1['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename1='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded1['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) { $thumbnail_width = 100; $thumbnail_height = (int)(100 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(100 * $size[0] / $size[1]); $thumbnail_height = 100; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail $destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } //file2 while( $counter <= count($photos_uploaded2) ) { if($photos_uploaded2['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded2['type'][$counter], $known_photo_types)) { $result_final2 .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos(`photo_filename2`) VALUES('0')" ); $new_id = mysql_insert_id(); $filetype = $photos_uploaded2['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id."_1.".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename2='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded2['tmp_name'][$counter], $images_dir."/".$filename); $result_final2 .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final $result_final2 </body> </html> __HTML_END; ?> </code> what is the simple way to upload a photo to mysql or store in a dir, and update the database with the new url? Hey Guys, I have a php script that update's franchise information using a mysql table. Note: Ter = Territory, ie. the territory that franchise covers. <?php include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { //Photo Upload //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 $photo =($_FILES['photo']['name']); //Pause Photo Upload foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '{$_POST['photo']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); //Unpause Photo Upload //Writes the photo to the server move_uploaded_file($_FILES['photo']['tmp_name'], $target); //End of Photo Upload echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> In phpmyadmin I can see my table and it has the correct image name displayed in the photo column. So you would assume its worked. But when I look in the 'images/' location no image has been uploaded. So I think there is an error with the upload part but cant figure out whats wrong. Cheers, S I wonna to upload photo with js and ajax.. i can do inserting something in mysql, but i dont know how to do with files :/ Form: Code: [Select] <form enctype="multipart/form-data" method="get"> <center> <label>Title: <input type="text" name="s_name" value="" style="width:250px" /></label> <label>Image: <input type="file" name="s_image" style="width:250px" /></label> <input class="button" type="submit" name="s_add" value="Add" style="width:100px" OnClick="save();" /> </center> </form> This is js code: Code: [Select] function save() { col = document.getElementById("new"); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { col.innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","sources/save.php?i dont know what to insert here,true); xmlhttp.send(); } this is save.php: Code: [Select] <?php $allowed_size = 204800; $name = $_GET['name']; $name = $_GET['image']; $date = time(); if (save_img($up_imgfile, $up_imgname, $allowed_size)) { $query = "INSERT INTO table (name, image, date) VALUES ('{$name}', '{$image}', '$date')"; $result = mysql_query($query, $connection); if ($result) { echo "<p class='warn-green'>$season_name has been successful added</p>"; } else { echo "<p class='warn-red'>Error: $season_name is not added, try again.</p>"; } } } ?>save_img() is php function to upload photo and make thumb.. How can i do this thing to do this function, but i need this: $up_imgname = $_FILES['s_image']['name']; $up_imgfile = $_FILES['s_image']['tmp_name']; Becouse of that i cant do this, how can i get temp name, image name of uploaded file ? hello all, i have a photo uploader that clients use. i want this to be able to put clients photos in there own folder within a specified path. $(function() { $('#custom_file_upload').uploadify({ 'uploader' : '/uploadify.swf', 'script' : 'uploadify.php?user=<?php echo("$logged[ip]"); ?>', 'cancelImg' : '/cancel.png', 'folder' : '/wuploads/{$logged('email')}', 'multi' : true, 'auto' : true, 'fileExt' : '*.ZIP;*.zip;*.rar', 'queueID' : 'custom-queue', 'queueSizeLimit' : 1000, 'simUploadLimit' : 1000, 'removeCompleted': true, 'onSelectOnce' : function(event,data) { $('#status-message').text(data.filesSelected + ' files have been added to the queue.'); }, 'onAllComplete' : function(event,data) { $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.'); } }); }); i have tried the code above with 'folder' : '/wuploads/{$logged('email')}', but this doesnt seem to work, im new to php and tried a few different combinations but it wont budge! thanks, gavin Hello, can you help me on my news article? I would like to be able to add photo on the article. Below is my codes Quote ======= html ======= <?php include_once ('post_news.php'); ?> <form Action="add_news.php" Method="post"> <input name="postdate" type="text" id="postdate"> <input name="title" type="text" id="title"> <textarea name="newstext" cols="60" rows="15" id="newstext"></textarea> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"> </form> ============== php - post_news.php ============== <?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { require_once ('inc/dbConfig.php'); // Define the query. $query = "INSERT INTO news (id, postdate, title, newstext) VALUES (0,'{$_POST['postdate']}', '{$_POST['title']}','{$_POST['newstext']}')"; // Execute the query. if (@mysql_query ($query)) { print "<p>Data has been added.</p>"; } else { print "<p>Could add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } mysql_close(); } ?> ===== db structure ====== id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14), title varchar(50) NOT NULL, newstext text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate) Hope you guys can help me. Thanks! Hi all, i've set this script for my gallery, it works, it display me the name of the albums, but when i click to see the pictures inside, the page is blank, and also don't appear the "Back to the albums" link, i can't find the error in the code... Code: [Select] <html> <head> <script type="text/javascript" src="../lightbox2.05/js/lightbox.js"> </script> </head> <body> <?php $page = $_SERVER['PHP_SELF']; //settings $column = 5; //directories $base = "carrelli_noleggio"; $thumbs = "thumbs"; // get album $get_album = $_GET['album']; //if no album selected if (!$get_album) { echo "<b>Select an album:</b><p />"; //find each album and display as links $handle = opendir($base); while (($file = readdir($handle))!==FALSE) { if (is_dir($base."/".$file) && $file != "." && $file != ".." && $file != $thumbs) { echo "<a href='$page?album=$file'>$file</a><br />"; } } closedir($handle); } else { //check if album exist, and additional security checks if (!is_dir($base."/".$get_album) || strstr($get_album,".") !=NULL || strstr($get_album,"/") !=NULL || strstr($get_album,"\") !=NULL) { echo "Album doesn't exist."; } else { $x = 0; echo "<b>$get_album</b><p />"; $handle = opendir($base."/".$get_album); while (($file = readdir($handle)) !== FALSE) { if ($file != "." && $file != "..") { echo "<table style='display:inline;'><tr><td><a href='$base/$get_album/$files' ref='lightbox'<img src='$base/$thumbs/$file' height='100' width'100'></a></td></tr></table>"; $x++; if ($x==$column) { echo"<br />"; $x = 0; } } } closedir($handle); echo "<p /><a href='$page>Back to albums</a>"; } } ?> </body> </html> G'day, on the home page of a website i'm building, i'm wanting to have a random photo that looks at all the subfolders of the gallery directory, but the best I can achieve is just one subfolder. Here is the code, if anyone can assist, that'll be appreciated. <?php function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); $num = array_rand($ar); return $ar[$num]; } function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } $root = ''; // If images not in sub directory of current directory specify root //$root = $_SERVER['DOCUMENT_ROOT']; $path = 'gallery/topic1/'; // Obtain list of images from directory $imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList); ?> <center><a href="?GoTo=Photo Gallery"><img src="<?php echo $path . $img ?>" alt="" height="267" width="400"/></a></center> Hi, I am making login page with database and php. I need to be able when the person clicks theogin button to take photo of the person and add it to that same database based on the info entered.
I am doing this to know if that person that logged in is the person in reality.
Is it possible adding photo,Array ( [name] => profilepic.jpeg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\phpB923.tmp [error] => 0 [size] => 152127 ) Hi, We have been using this code for ages, but suddenly for some reason we cannot upload an image using the code below. When we try to Print_r the $profilephoto variable, I get this error. The filename is correct, but what is that [error]?? And how do I resolve it? Oddly it does upload it locally, but LIVE, it won't This is the code. if (isset($updatephoto)) { echo "adding photo,"; print_r($profilephoto); define ("MAX_SIZE","5000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["profilephoto"]["name"]; $uploadedfile = $_FILES['profilephoto']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['profilephoto']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo "Unknown Extension..!"; } else { $size=filesize($_FILES['profilephoto']['tmp_name']); if ($size > MAX_SIZE*1024) { echo "File Size Excedeed..!!"; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['profilephoto']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['profilephoto']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); echo $scr; } list($width,$height)=getimagesize($uploadedfile); $newwidth=600; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $pic=($_FILES['profilephoto']['name']); $random = (rand()%99999999); $newname="$random"."$pic"; $filename = "images/profiles/". $newname; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); }} } $query = ("UPDATE users SET profilephoto =:newname WHERE id =:userid"); $result = $pdo->prepare($query); $result->execute(array(':userid' => $userid, ':newname' => $newname)); echo "<script> window.location.replace('/profile/') </script>";}
I have used the same method for uploading photos for ages but feel there may be a better way. For both methods, please assume all uploads are large digital camera uploads of a few megabytes and thousands of pixels wide (as you would expect from large digital camera images). CURRENT METHOD (1) receive uploaded file and use ImageMagick to convert to 4 file sizes, then store these file sizes (also set so ImageMagick reduces the quality to something like a setting of 80 out of 100 which will further reduce file size. - file sizes (widths): 800 240 120 60 (mobile phones etc.) (2) Based on the type of size and view required I then use <img src="/photos/240/file.jpg to display (240 being the required image size of course) POSSIBLE BETTER METHOD (1) Use ImageMagick to reduce to 800 wide as will never display bigger than this anyway, reduce quality also. But don't resize further and only need one file. (2) Use PHP commands to display an image, and set height/width/quality then. Eg: <img src="showImage.php?file=file.jpg&width=240&quality=60 So both would do the same thing but the second seems better as you don't need to create 4 images for every photo upload. Why make lots of thumbnails when you can make one and then get PHP to create at the time of display? Although I suppose if you regularly displayed these images in a search result then PHP would need to do that extra processing on every search. Creating all 4 at the time of upload only requires the one bit of processing. Have I just found the answer? Hello. I want to display all photos from the database. The problem is that it displays nothing. I added a foreach loop in html but further it not display. I'am beginner, I hope someone help me where I make mistake. I care about separation logic from view.
class photo_display { private $database; private $userData; public function __construct($database) { $this->database = $database; } public function display() { $query = $this->database->connect()->prepare("SELECT photo FROM photo"); $query->execute(); if ($query->rowcount()) { $row = $query->fetchAll(); } $this->userData = $row; } public function display_Photos(string $colName) { return (isset($this->userData[$colName])) ? $this->userData[$colName] : []; } } <div class='container-fluid bg-dark' id='profil'> <div class='row'> <div class=" col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4 order-5 order-12 order-6 order-md-4"> <div class="row" id="margin"> <div class="col-xl-12 d-flex justify-content-center" id="test"> <?php foreach ($photo_display->display_Photos('photo') as $value) { ?> <img src ="<?php echo var_dump($value) ?>" />; <?php } ?> </div> </div> </div>
People upload photos to my site. They go into a gallery. They are all linked. Right now when you click one they go nowhere. I want to be each photo to open in its own page with my comment system already on it. Should I be using templates? If so how? Heres code to the gallery page if needed. And I'm using dreamweavers server behaviors. If that will cause a problem let me know. Still new to PHP but getting better...maybe. Sorry to keep asking noob questions. Code: [Select] <?php require_once('myconn.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 40; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_myconn, $myconn); $query_Recordset1 = "SELECT name, photopath, `state` FROM photo"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <div id="photos"> <table border=""> <?php $i=0; $numperpage=8; ?> <?php do { ?> <?php if ($i%$numperpage==0) echo "<tr>"; ?> <td align="center"> <a href=<?php echo $row_Recordset1['photopath']; ?>/> <img src=<?php echo $row_Recordset1['photopath']; ?> height="200" width="200"/> <br/> <?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td> <?php $i++; if ($i%$numperpage==0) echo "</tr>"; ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </div> </body> </html> <?php mysql_free_result($Recordset1); ?> Hello: I am working with a script that I am using to make a player roster - the user can add a photo, player title, number, years played, and a bio. The data comes from a submit form, then goes to the code below to process everything. It works fine if a photo is added, but if a photo is not added, the script does not work. Any idea why, and how I can fix it? Code: [Select] <?php // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); $photos_uploaded = $_FILES['photo_filename']; $player_title = $_POST['player_title']; $player_number = $_POST['player_number']; $years_played = $_POST['years_played']; $photo_caption = $_POST['photo_caption']; while( $counter <= count($photos_uploaded) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { //mysql_query( "INSERT INTO gallery_photos(`photo_filename`,`player_title`,`player_number`,`years_played`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ); mysql_query( "INSERT INTO gallery_photos(`photo_filename`,`player_title`,`player_number`,`years_played`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($player_title[$counter])."', '".addslashes($player_number[$counter])."' , '".addslashes($years_played[$counter])."', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ); $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) //{ //$thumbnail_width = 100; //$thumbnail_height = (int)(100 * $size[1] / $size[0]); //} //else //{ //$thumbnail_width = (int)(100 * $size[0] / $size[1]); //$thumbnail_height = 100; //} { //$thumbnail_width = 690; //$thumbnail_height = (int)(500 * $size[1] / $size[0]); $old_width = $size[0]; $old_height = $size[1]; $thumbnail_width = 690; $thumbnail_height = ($old_height * $thumbnail_width / $old_width); } else { $thumbnail_width = (int)(690 * $size[0] / $size[1]); $thumbnail_height = 500; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail //$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height ); $destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' style='margin-right: 20px; width: 100px;' />"; } } $counter++; } // Print Result echo <<<__HTML_END $result_final __HTML_END; ?> Thanks! |