-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
post code... -
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
you can restrict the file size of uploaded files with the file-size value... -
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
post code? -
thats incorrect syntax. It looks like this $id = (isset($_POST['id'])) ? $_POST['id'] : ''; you mixed up the ternary operator with the colon
-
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
sure! lets break it down into steps $str = substr($fileName, strrpos($fileName, '.') + 1); the first function called is substr. This will take a part of the string (the first parameter) from the startposition of the second parameter. (there is also a 3rd parameter called length that will specify the length of the substr. if not specified it will take the string from the start position to the finish position. for example $hello = "Hello World"; echo substr($hello, 2);// llo World echo substr($hello, 0);//Hello World echo substr($hello, 1, 4);// ello Now the second parameter has another function call, which isstrrpos). This will get the string position of the last occurence of the second parameter, from the string in the first parameter. In this case, we look for the period character in the $fileName string. Say we have "myFile.jpg" strrpos will return the position 6 if we were to look for the period. (Note, strings are 0 based, so the first character will be in position 0) We add 1 to the string position of the period character because we want everything after the period (IE the file extension). that line is basically like doing $fileName = "file.php"; $ext = substr($fileName, 5);//5 is the position of the p in php, or the position of the period + 1 but it works for any file names/file types. also works for multiple periods in 1 file, since strrpos finds the last occurence of the second paramter -
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
... I just posted code to check the extension... use what I posted -
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
yes, because mozilla provides the Mime type. obviously IE isn't providing one, or is providing a different one. If you want it to work across all browsers, don't rely on mime type, rely on the file extension. -
Warning: include(include/solo2) [function.include]: failed to open stream: No such file or directory in /home/.../public_html/page.php on line 20 that error means that whatever page you are trying to include could not be found at the path specified. Make sure that your file name and file path are correct
-
[SOLVED] get confused with uploaded file
mikesta707 replied to robert_gsfame's topic in PHP Coding Help
Getting the mime type as a check for if the file is actually an image file or not is not the best practice. Mime types can be spoofed, and not all browsers even send a mime type. you should get the extension via substr and test that. like so $ext = substr($fileName, strrpos($fileName, '.') + 1);//$fileName is the name of the file if ($ext != 'jpg' || $ext != 'jpeg'){ echo "Wrong file type"; exit(); } -
I'm not sure, but i read this on the PHP manual system()
-
assuming that the array is already pre-sorted, and it will ALWAYS be presorted, /*will return an array of the keys that had a ties. this function assumes that the first key $array[0] is the high score also assumes its a numeric array Does include the first array($array[0])'s key. will always */ function getTies($array){ $highest = $array[0]; $keys = array(); foreach($array as $key = > $arr){ if ($arr == $highest){ $keys[] = $key; } } return $keys; } Haven' tested it though, so it may take some tweaking
-
<?php function doImages(){ $image_array=array("http://t1.gstatic.com/images?q=tbn:kgc1p_6ThobetM:http://www.anthonyshapley.co.uk/wp-content/php_2.jpg","http://images.google.co.uk/imgres?imgurl=http://www.gnunify.in/09/images/php.png&imgrefurl=http://www.gnunify.in/09/content/php-marathon&usg=___8eUuwdxDW7MS8BVapZbXcnlVwg=&h=376&w=576&sz=82&hl=en&start=1&tbnid=6k7fLwXklbmkPM:&tbnh=87&tbnw=134&prev=/images%3Fq%3Dphp%26gbv%3D2%26hl%3Den%26sa%3DG"); foreach($image_array as $images){ echo $images; } } class showImages{ // this is the error code? public $image=doImages(); } $img = new showImages(); echo "{$img->image}"; ?> well you aren't returning anything with that function, you are echoing things, so thats why you get the error As for the other stuff. Its basically saying that in order to use a member function of a class, you have to use the "->" operator with the object on the left, and the method on the right. The same principle applies when accessing data members also, except you are calling a function. If you have ever used javascript before, you are probably familier with calling methods and data members. for example, the document object has a write method that you should be familiar with. document.write("Hello World!"); in Javascript, (as well as many other languages) unlike PHP instead of the -> operator, it used the "." operator. Did that answer your question? I'm not quite sure what it was
-
[SOLVED] explaination needed please! for $SQL
mikesta707 replied to samoi's topic in PHP Coding Help
well, that is wrong first off. but ignoring that it basically means that $row is a multidimensional array, or an array of arrays. say for instance we had an array definition that looked like $arr = array(0=>array("array", "of", "different", "strings"), 1=> array("More", "strings")/*etc.. */); the first index, accessed by $row[0]; which is an array with 4 different entries. You can also access the first index of the array at index 0 by doing $row[0][0] if I were to echo that it would say "Array" if I were to output stuff like so echo "I am an " . $row[0][0] . " " . $row[0][1] . " " . $row[0][2] . " " . $row[0][3]; the output would be I am an array of different strings. Just think of it as a table. the first set of brackets is the row, and the second is the column Now for why thats wrong. The function mysql_fetch_array() only returns a single dimension array with the elements that your SQL query returned from one row That means that doing that function will only return the first row of your sql return set. if you want everything, you have to iterate through the array, like so $query="select timediff(dueTime, now()) from store where userid=".$id; $result=mysql_query($query, $db_id); $allTheRows = array(); while($row = mysql_fetch_array($result)){//this is the key part $allTheRows[] = $row//this pushes the content of $row into the array allTheRows } now you could do echo $allTheRows[0][0]; and that would echo the first column of the first row returned. However in your code, the array $row is 1 dimensional, and it is being accessed if it were two dimensional. which will probably throw error. -
you could make each a link with a get variable, and you order by that get variable.
-
[SOLVED] string represenation of number as number
mikesta707 replied to mikesta707's topic in PHP Coding Help
thanks mark, the specific function you linked to is the opposite of what I want though hehe, (its ints to words, not words to ints). I was going to write the function but just wanted to know if there was a built in one already. thanks everyone -
define the array on showimage.php and with the post variable arrayresult do the following echo $alert[$_POST['arrayresult']]; if you cant define the array on showimage.php then pass it through the session, or serialize it and pass it through a post variable (though I would just pass it through the session)
-
[SOLVED] string represenation of number as number
mikesta707 replied to mikesta707's topic in PHP Coding Help
Won't work. casting strings to ints only works when you have an int surrounded by quotes, like "2" or "5" or "15", however if you use the word, IE "two", "five", or "fifteen" they get cast to zero (as do all other non integer strings) -
seems that way
-
yes when you submit a file field, it uploads the file to the servers temp folder. Upload scripts don't really upload the file perse, they move the file to a more permanent destination (files in the temp folder get deleted after a little bit)
-
Is there a function that will take the string representation of a number, and return the number it represents? IE if the string was fifteen, it would return 15, etc?
-
$_FILES['file']['name'] gives the filename that was on your specific computer I believe (IE if you uploaded myname.jpg, than that would return myname.jpg) the problem is that the particular file myname.jpg doesn't exist on your server until you move it from the temp folder (assuming you move it with the same name as it had). $_FILES['file]['temp'] gives the file name of your file in the temporary folder I think, so you may be able to do it with that.
-
ahh ok. It is quite easy, not any harder than writing to files, you will just have to get used to queries and such. Here is a tutorial on it.
-
yes, have you used PHP's mysql functions at all?