Jump to content

unistake

Members
  • Posts

    445
  • Joined

  • Last visited

Everything posted by unistake

  1. Ok got there, works perfectly. Thanks for the tip on the reg. will do.
  2. The value $_GET['reg'] is taken from www.websiteexample.com/index.php?reg=abcd The images are stored in a directory off where the scripts are called 'aircraft' In the script I am trying to show all the images (if there are any) that are stored called abcd1.jpg, abcd2.jpg etc up to abcd9.jpg If anyone has a better way to do it please tell me! I thought a foreach would be best.???
  3. I am using the script below but I am getting no return, and a white screen. <?php while($i=0 $i < 9 $i++) { echo '<li class="active"><img src="./aircraft/' . $_GET['reg'] . $i . '.jpg" alt="test"><br />'; } ?>
  4. I think I am missing something from your post above, I cant find a difference. I put both the $file[] array and echo in the while loop.
  5. Like this? Something is still wrong? <?php while($i=0 $i < 9 $i++) { $file[] = "aircraft/".$_GET['reg'].$i.".jpg"; echo "<li class=\"active\"><img src=\"./aircraft/$file.jpg\" alt=\"Flowing Rock\" style=\"width: auto; height: 70px; margin-left: -28.5px; display: block;\" class=\"thumb\" ><br />"; } ?>
  6. hi all, I have possibly up to 9 images that I want to find and show on a webpage. I am trying to put a $file in a loop and get all the .jpg images that are found in to an array and show them all. I think from the script you can see what I am attempting to do! Any pointers would be grateful for <?php while($i=0 $i < 9 $i++) { $file = "aircraft/".$_GET['reg'].$i.".jpg"; } foreach($file) { echo "<li class=\"active\"><img src=\"./aircraft/".$reg.$i.".jpg\" alt=\"Flowing Rock\" style=\"width: auto; height: 70px; margin-left: -28.5px; display: block;\" class=\"thumb\" ><br />"; } ?>
  7. hi all, I am trying to link 2 mysql tables and display some information from each of them. I have a list of all the possible items for sale in table1 and I am trying to count the number of rows in the other table2 where the items exist. E.g. 'table1' manufacturer model man1 item1 man1 item2 man1 item3 'table2' id model 1 item3 2 item3 3 item2 And the result would show: item1(0) item2(1) item3(2) It would list all the items from table1 and show next to it how many rows are related to that item from table2. I have inserted a quote where I have tried many times to enter something similar to that show in the note below - but I can not get it to work - it just shows the total number of models in table1 for a given manufacturer. The php I have made so far is: <?php case 'manufacturer': $query = " SELECT * FROM table1"; $query .= " WHERE manufacturer = '".$data."' "; $query .= " ORDER BY model "; $result = mysqli_query($cxn,$query); $returnData[''] = "Select a Model..."; while($row = mysqli_fetch_assoc($result)){ // I THINK I NEED TO INSERT SOMETHING LIKE $query2 = "SELECT * FROM table2 WHERE model = table1.model"; $k=$row['model']; $k2=$row2['model']; $counter[$k]+=1; $returnData[$k]=$k; } foreach($counter as $k => $row) { $returnData[$k] .= " ($row)"; } break; ?>
  8. could you use echo $day."-".$month."-".$year;
  9. ok, what would this come up as in the web browser? would it show example.com/mine or example.com/profile.php?username=mine? I will use that if it shows example.com/mine.
  10. Hi all, I want to place the form submit button/image inside the search input box. Could someone direct me to a tutorial or give help to make this. Example: http://www.bing.com/ Thanks
  11. Hi Thorpe, Thanks for the advice, I was thinking the same but for my website I want each user to have their own directory such as www.website.com/mine so that they have a memorable web name to pass on to their friends. I am fully aware that one php can do all but I just wanted this directory for the above use. In question to your comment, is there a way then of just adding an index.php page to the new directory then, and displaying all the information relating to that new directory name? e.g. www.website.com/mine $directoryname = 'mine' from domain above. $sql = "SELECT * FROM table WHERE id='$directoryname'"; How would I get the directory name in to a variable? Thanks.
  12. Hi all, I am using php to allow users to create a new directory e.g. www.website.com/theirname/ and would like to auto generate an index.php (or index.html) page if possible within this directory. Any tips on how to do it would be appreciated. The code I have for generating the directory is: <?php function handleError() { trigger_error('MY ERROR'); /** usage sample @handleError(); echo $php_errormsg; */ } // detect slash/backslash nomenclature dirname $path = dirname( __FILE__ ); $slash = '/'; (stristr( $path, $slash )) ? '' : $slash = '\\'; define( 'BASE_DIR', $path . $slash ); $folder = $_POST['reg']; // folder name $dirPath = BASE_DIR . $folder; // folder path // print results echo $slash; echo '<hr>'; $rs = @mkdir( $dirPath, 0777 ); @handleError(); if( $rs ) { // print success information echo 'was done!'; echo '<br>folder: <a href="' . $folder . '">' . $folder . '</a>'; echo '<br>dirPath: ' . $dirPath; }else{ // print error information echo "This webpage <b>www.website.com/".$folder."</b> appears to have been already been created. Please try another web name. If the problem persists please report it to us."; } ?>
  13. One last thing, Is there a way of adding a like 'loading' gif image while the users wait for the uploads?
  14. Hi Andy, I am testing live. It was because .JPG was not accepted as an extension. Thanks for your help. works amazingly! Cant say how much of a help you have been! I will post you the website once I have it running.
  15. I am trying to upload jpg images but it is saying the $err "file not an image, you can only upload .jp(e)g or .png files."; Can this be changed easily?
  16. Try this: $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } } echo " <tr> <td colspan=\"2\" style=\"font: 10px verdana,sans-serif; color: #3399AA;\">'.$m.'</td> </tr></table><br>"; flock($file, LOCK_UN); fclose($file);
  17. Ok thanks andy. The script uploads the image to '/aircraft' and creates a thumbnail to the same /aircraft directory. The name of the image will be using the $reg variable (above $reg= "G-BAAA"). As there are more than one images that I am trying to get to upload, I want to rename all the images like G-BAAA1.jpg and G-BAAA2.jpg etc. The thumbnails will be called G-BAAA_thumb.jpg respectively. That is it. I am also going to try and cut the larger image to a size 600px x 400px but I will do this after I have got the script to store more than one image. Thanks for your help.
  18. Hi Andy, Thanks for that. Could you just walk me through what those variables are for? I have a variable in my script $filename = stripslashes($_FILES['image']['name']); How would I use your variable of $name = basename($files[$i]['name']); with this? Thanks The whole script I have is: <?php $reg = "G-BAAA"; if ( isset($_POST['Submit']) ) { $dir = 'aircraft/'; $files = array_values($_FILES); $number = count($files); for ($i = 0; $i < $number; $i++) { $name = basename($files[$i]['name']); $dir .= $name; //define a maxim size for the uploaded images define ("MAX_SIZE","40000"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","200"); define ("HEIGHT","100"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message //and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$reg.$number.".".$extension; //the new name will be containing the full path where will be stored (images folder) $newname="aircraft/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='aircraft/thumb_'.$image_name; // call the function that will create the thumbnail. The function will get as parameters //the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created if(isset($_POST['Submit']) && !$errors) { echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } } } ?> <!-- next comes the form, you must set the enctype to "multipart/form-data" and use an input type "file" --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><input type="file" name="image" ></td></tr> <tr><td><input type="file" name="image" ></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form>
  19. Hi all, I have a long script that processes only one image at the moment. What I am trying to do is put all the script in to a 'foreach' section so that I can process more than just one image. Could someone show me how to do this, putting all the uploaded images in to an array (i guess is the best option) and tell me what the form input names need to be below. The script I was trying to make in principle was: <?php $reg = "G-BAAA"; $count-number-of-files-being-uploaded = x ; // NUMBER OF FILES?? $number = 0; foreach $_FILES { // THIS IS WHERE THE IMAGES ARE UPLOADED AND THUMBNAILS CREATED. THE NAMES OF THE FILES ARE $reg.$number."."$ext; $number++; } ?> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><input type="file" name="image[]" ></td></tr> <tr><td><input type="file" name="image[]" ></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form>
  20. Hi all, I have been trying to create a thumbnail but have realised I can just resize the image instead. I have been trying to do this and have made the code below however do not know what else I need to do to upload the new image. Could someone help? Thanks <?php $filename = $_FILES['image']; $reg = "G-ZZZZ"; $width = 200; $height = 200; list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); ?>
  21. Can anyone help? I just want to resize the image before I upload it. <?php $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); ?>
  22. I cant see what the $filename is?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.