Jump to content

gggggggg

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gggggggg's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, not sure if i should have started a new topic or not, so went with sticking to this one. I followed this post to the letter, it worked perfect. But then I realised there are limitations about the size of a URL and what can be passed over a URL. e.g. a & sign. I want to send maybe 5000 characters. Any suggestions, and by the way, this is my first ajax/js attempt, so I will need all the steps please. thanks for your help g
  2. love your work nafetski, thanks. It works now.
  3. Hello, I have some code to allow image file uploads to MySQL. Except I want to be able to save 2 copies of the image. 1) The origional 2) A thumbnail size 150x150 copy next to the origional. Here is the error I get. Is anyone able to help, or let me know of a better way Warning: imagesx() expects parameter 1 to be resource, string given in C:\wamp\www\Working\uploads\test\1.php on line 73 Warning: imagesy() expects parameter 1 to be resource, string given in C:\wamp\www\Working\uploads\test\1.php on line 74 Warning: imagecopyresampled() expects parameter 2 to be resource, string given in C:\wamp\www\Working\uploads\test\1.php on line 75 Warning: imagedestroy() expects parameter 1 to be resource, string given in C:\wamp\www\Working\uploads\test\1.php on line 76 Thank you Below is my code: <?php $db_host = 'localhost'; // don't forget to change $db_user = 'root'; $db_pwd = ''; $database = 'test'; $table = 'ae_gallery'; // use the same name as SQL table $password = '123'; // simple upload restriction, // to disallow uploading to everyone if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query $thumbdesired_width = 150; $thumbdesired_height = 150; $im = $data; $new = imagecreatetruecolor($thumbdesired_width, $thumbdesired_height); $x = imagesx($im); $y = imagesy($im); imagecopyresampled($new, $im, 0, 0, 0, 0, $thumbdesired_width, $thumbdesired_height, $x, $y); imagedestroy($im); //header('Content-type: <span class="posthilit">image</span>/jpeg'); //imagejpeg($new, null, 85); mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', data='$data', thumb='$new' "); $msg = 'Success: image uploaded'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>MySQL Blob Image Gallery Example</title> </head> <body> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> <h1>Blob image gallery</h1> <h2>Uploaded images:</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No images loaded</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title) = mysql_fetch_row($result)) { // outputing list $PHPSELF = $_SERVER['PHP_SELF']; echo "<li><input type='radio' name='del' value='{$id}'>"; echo "<a href='$PHPSELF?show={$id}'>{$title}</a> – "; //echo "<a href=''PHP_SELF'?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></li>"; } echo '</ul>'; echo '<label for="password">Password:</label><br>'; echo '<input type="password" name="password" id="password"><br><br>'; echo '<input type="submit" value="Delete selected">'; } ?> </form> <h2>Upload new image:</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> <label for="title">Title:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="photo">Photo:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> </body> </html>
  4. Thats what I though also, but I treid this, and it didnt work: //get the value of the available options value $options = $_POST['availableOptions']; echo $options ; It told me: Notice: Undefined index: availableOptions in xxxxxxxxxxxx Line 7 I have attached my source, mayby that will help. [attachment deleted by admin]
  5. sorry, those other accounts are nothing to do with me.
  6. heheheheheeh. I had snags for dinner.
  7. Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but hit a snag. I have 2 list boxes, that I use to move items left to right. When I click submit I want to load the items selected into MySQL. Is anyone able to help please? I can do the insert into MySQL (i think), but i cant work out how to get the values into a variable that PHP can use to submit. Then to make it more complicated, once I have it working for 1 list, I ideally wany about 10 lists on the page (with only 1 submit box). I am lost. Thanks greg This is my OPTION.js file var selectedList; var availableList; function createListObjects(){ availableList = document.getElementById("availableOptions"); selectedList = document.getElementById("selectedOptions"); } function delAttribute(){ var selIndex = selectedList.selectedIndex; if(selIndex < 0) return; availableList.appendChild(selectedList.options.item(selIndex)) selectNone(selectedList,availableList); setSize(availableList,selectedList); } function addAttribute(){ var addIndex = availableList.selectedIndex; if(addIndex < 0) return; selectedList.appendChild(availableList.options.item(addIndex)); selectNone(selectedList,availableList); setSize(selectedList,availableList); } function delAll(){ var len = selectedList.length -1; for(i=len; i>=0; i--){ availableList.appendChild(selectedList.item(i)); } selectNone(selectedList,availableList); setSize(selectedList,availableList); } function addAll(){ var len = availableList.length -1; for(i=len; i>=0; i--){ selectedList.appendChild(availableList.item(i)); } selectNone(selectedList,availableList); setSize(selectedList,availableList); } function selectNone(list1,list2){ list1.selectedIndex = -1; list2.selectedIndex = -1; addIndex = -1; selIndex = -1; } function setSize(list1,list2){ list1.size = getSize(list1); list2.size = getSize(list2); } function getSize(list){ /* Mozilla ignores whitespace, IE doesn't - count the elements in the list */ var len = list.childNodes.length; var nsLen = 0; //nodeType returns 1 for elements for(i=0; i<len; i++){ if(list.childNodes.item(i).nodeType==1) nsLen++; } if(nsLen<2) return 2; else return nsLen; } function showSelected(){ var optionList = document.getElementById("selectedOptions").options; var data = ''; var len = optionList.length; for(i=0; i<len; i++){ if(i>0) data += ','; data += optionList.item(i).value; } alert(data); } This is my edit.php file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Test</title> <script type="text/javascript" src="option.js"></script> </head> <body onload="createListObjects()"> <?php echo" <select name=\"selectedOptions[]\" id=\"selectedOptions\" multiple=\"true\"> "; //start the select box echo "<option value=\"1\">Cat</option>\n"; //and place it in the select echo "<option value=\"2\">Dog</option>\n"; //and place it in the select echo "</select>"; //close the select ?> <button onclick="addAttribute()"><</button> <button onclick="addAll()"><<<</button> <button onclick="delAttribute()">></button> <button onclick="delAll()">>>></button> </td> <?php echo" <select name=\"availableOptions\" id=\"availableOptions\" multiple=\"true\"> "; //start the select box echo "<option value=\"3\">pig</option>\n"; //and place it in the select echo "</select>"; //close the select ?> <tr> <td colspan="2"><button onclick="showSelected()"> Submit</button> </td> </tr> </body> </html> <html><body> <?php $data = $_POST['selectedoptions']; I AM LOST HERE echo "Data Inserted!"; ?> </body></html>
×
×
  • 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.