Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
gibbed
Apr 10, 2006

Battle Bott posted:

Which is exactly what I'm doing. I don't want to serve files, I want to *execute* them, and if they don't execute, I want to pass them on.
You want to execute arbitrary code uploaded by random people? :raise:

Adbot
ADBOT LOVES YOU

gibbed
Apr 10, 2006

drcru posted:

I'm storing a list of integers in a comma separated textfield on MySQL and then explodin them into an array. I then check through a list of 25 integers and see if they are on the original list. Is there a better way to do this?

php:
<?
$galaxy = "144,145,119,118,117,92,93,68,69,70,91,116";

$explored = explode(",", $galaxy);

// this is done in a loop up to 25 times
if( in_array($current, $explored) )
{
echo "blah";
}
?>
array_intersect.

gibbed
Apr 10, 2006

drcru posted:

How come it won't let me overload this function with time()? I seem to be able to do it with array()...

php:
<?
public function get_foo_bar( $cutoff = time() )
{
//
}?>
"Parse error: syntax error, unexpected '(', expecting ')' in "
array() is a language construct, not a real function.

gibbed
Apr 10, 2006

You could do something like this instead, though:
php:
<?php
    public function get_foo_bar($cutoff false)
    {
        if ($cutoff === false)
        {
            $cutoff time();
        }
    }
?>

gibbed
Apr 10, 2006

Doesn't mysqli force you to bind variables?

gibbed
Apr 10, 2006

Golbez posted:

just to realize that bind_param probably doesn't work that way; for it to work, I'll have to load all of those getDatas into individual variables, then bind THOSE. Yet I still want to have a secure input; back to mres() for me, I guess. Oh, and a new one: Apparently mysqli_bind_param doesn't support NULLs! Well that's just loving great. So now I have to dynamically edit the query as well?

Zend_DB is looking kind of nice. I think I need a beer.
Yes, that's what I meant, bind_param requires variables to bind to, whereas in PDO you can just do $statement->execute(array($var1, $var2, ...)) (this probably isn't the correct names but you get the idea). And you can bind variables too, if you want to.

gibbed
Apr 10, 2006

SpoonsForThought posted:

I'm new to php so I'll answer these the best I can.

I use a Mac, and I'm not sure of the server type as it is my university's web space that I'm upload thing to. There is literally one line about the server and it says it supports PHP scripting.
Upload a PHP script with the contents <?php phpinfo(); and access it. The output of phpinfo should give sufficient information about the server and php's configuration.

(and of course, don't leave that script there, remove it when you're done)

gibbed
Apr 10, 2006

Begby posted:

What do you mean by faster? Like take less processor time? Or do you mean that with ++$i you will see $i incremented within the statement, while $i++ sees the value incremented afterward? If you mean the latter that is by design and how it works in all languages that support the ++ operator.
Apparently the PHP devs actually have cocked it up to where pre-increment is actually faster than post-increment. :woop:

(pre-increment doesn't copy a value where post-increment does)

gibbed fucked around with this message at 03:55 on Jul 13, 2009

gibbed
Apr 10, 2006

I wouldn't spit out raw binary to a browser for it to resubmit, you should probably encode it somehow (base64, for example).

gibbed
Apr 10, 2006

Grawl posted:

php:
<?
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "upload/".$imagename;
move_uploaded_file($source, $target);
?>
This is insecure. The client has control over the 'name' value. You should sanitize it somehow, at least do basename().

Grawl posted:

php:
<?
$imagepath = $imagename;
$save = "upload/" . $imagepath; //This is the new file you saving
$file = "temp/" . $imagepath; //This is the original file
 
list($width, $height) = getimagesize($file);
?>

Grawl posted:

php:
<?
$image = imagecreatefromjpeg($file) ; 
?>
You've moved the uploaded file to upload/, not temp/, which is probably why this is failing.

gibbed
Apr 10, 2006

duz posted:

Good news! There's a secure image upload script written by R1CH in the first post!
It doesn't do thumbnails though, but yeah, it would be a good idea to hack on that one to add thumbnailing.

gibbed
Apr 10, 2006

supster posted:

php:
<?
$fh = fopen($newimage, 'r');
while(!feof($fh))
    echo fread($fh, 8192);
?>
No.

readfile

Edit: ignore this stupid advice

gibbed fucked around with this message at 00:38 on Jul 21, 2009

gibbed
Apr 10, 2006

supster posted:

readfile is avoided for the same reason
readfile doesn't read and output in chunks? That's horrible.

gibbed
Apr 10, 2006

Just read the code. Internally readfile() opens a handle to the file then uses passthru on the handle. The passthru code attempts to mmap the file and writes it out in that case, otherwise it reads the file in 8192 byte chunks and writes them out. So, I'm assuming the problem here is buffering rather than readfile itself, because readfile itself is fine.

gibbed
Apr 10, 2006

It's ideal to not use up more resources than you have to, even if the amount of resources are insignificant.

gibbed
Apr 10, 2006

haywire posted:

Dear PHP devs, what in the logic is removing the <?= shortcut along with the the <? shorttag? The <?= will not be confused with <?xml, and it is very useful for using php to template.

Which mailing list should I start a campaign on to have it reinstated?
I don't know (or care) about the echo tag, but I always disliked the short tag because it was a toggleable option to have it enabled or not.

gibbed
Apr 10, 2006

It's the equivilent of:
php:
<?
if ($field === TRUE)
{
    $field = $this->any_field;
}
?>
They're being jerks about the verbosity of their code basically.

gibbed
Apr 10, 2006

argz posted:

what?


<?=$my_var?>

is so much cleaner than

<?php echo $my_var?>


Do you like writing '<?php echo' 40 times in a file?
Short tag is <?, not <?=, and <?= is magic for <? echo.

gibbed fucked around with this message at 04:07 on Aug 29, 2009

gibbed
Apr 10, 2006

http://www.php.net/manual/en/book.ssh2.php

gibbed
Apr 10, 2006

haywire posted:

Is there any way to make php's shell_exec thing pretend to be a tty? Git is irritating as gently caress to work with from php. Does passthru do this?
proc_open?

gibbed
Apr 10, 2006

preg_replace("/\r?\n|\r/", "\n", ...)?

gibbed
Apr 10, 2006

As long as you're sanitizing the input file name it should be okay, although I would add a base path to the $filename and also check if the file exists too.

gibbed
Apr 10, 2006

eHacked posted:

Hate to ask this, it's probably stupidly easy.

I have this XML code:

code:
<?xml version="1.0"?>
<previewroot>
  <content>
    <names>
      <name name="watermark" num="78"/>
      <name name="thumb" num="83"/>
      <name name="jpg" num="78" filesize="5070011"/>
      <name name="hswmv" num="5" filesize="320274841" movie_length="1828.134"/>
      <name name="lswmv" num="5" filesize="37269332" movie_length="1828.172"/>
    </names>
I need to grab the "num" value from the name tag, with name="jpg".

I've been busting my fingers Googling this, but I'm just spinning my wheels.

Preemptive thanks for help!
I assume the XML you gave was simply incompletely pasted.

php:
<?
// $content is the XML content, obviously
$root = new SimpleXMLElement($content);
$names = $root->xpath('/previewroot/content/names/name[@name="jpg"]');
var_dump((int)$names[0]['num']);
?>

gibbed
Apr 10, 2006

Yay posted:

imagesX and imagesY.

No, I don't know why the functions are named as they are.
I've always figured it's imageSX and imageSY (as in, image size x, image size y).

gibbed
Apr 10, 2006

DholmbladRU posted:

I am attempting to create an update profile page on thie website, however I am having some trouble keeping multiple forms on the same page from affecting each other.

here is some psudo code for what I want to do
code:


execute if form1 was "submitted" {
some code		
}

execute if form2 was "submitted" {
    some code
	}
By searching online someone sugessted you name the forms, and then use the $_REQUEST to see if they are set.

php:
<?
    
if (isset($_REQUEST['submit2'])) { 
    if($Password1 = $Password2) 
        {
            code
        
            }
            
        }
?>
Everyone else seems to have missed this (and duplicated it in their code edits? :v:) but please learn your operators.

(I'm assuming this is an actual mistake made in your original code)

Adbot
ADBOT LOVES YOU

gibbed
Apr 10, 2006

PHP can open any size file the file system can handle, loading the file data into memory is what you're concerned about, and depends on the memory limit settings in php.ini.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply