Squidge 101 Newbie Poster

@LastMitch,

I am validating the mime type before progressing to the resizing OOP Class.

You are correct in the code you supplied, this is in the class functionalilty. I had created a multi array instead of one that i can validate the ['type'] from $_FILES.

So i cahnged the first line to:

$var = array('mimetype1','mimetype2');

And this parsed.

Thank you for your assistance and input. It is greatly received.

Squidge 101 Newbie Poster

Sorted:

$mime = array('image/gif','image/jpeg','image/jpg','image/png');
//$fileType = strtolower($_FILES['file']['type']);

if (in_array($_FILES['file']['type'], $mime)) {
    echo "You got it right, $fileType is accepted";
} else {
    echo "mime type is not allowed<br>";
}
Squidge 101 Newbie Poster

The first posted code works well, was hoping there maybe away round having to move_upploaded_file before running through the resize.

Thats a nice link thanks LastMitch, this is the one i used:

http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/

Resizes the file to many variations.

Could you look over the above file validation? Think i added is as you were posting :)

Squidge 101 Newbie Poster

It also appears my file validation is not working, it returns the file as not supported:

$excepted_EXT = array('image/gif' => 'gif',
    'image/jpeg' => 'jpeg',
    'image/jpg' => 'jpg',
    'image/png' => 'png');
$fileType = strtolower($_FILES['file']['type']);

if (in_array($fileType, $excepted_EXT) == TRUE) {
    echo "You got it right, $fileType is accepted";
} else {
    echo "WTF!!!!<br>";
    var_dump($excepted_EXT);
}

Even though the file is a jpg

Squidge 101 Newbie Poster

Evening all.

I am goign through my Image upload script and found it looks messy, would you recommend an cleaner way of doing this:

    move_uploaded_file($_FILES['file']['tmp_name'], 'photos/' . $_FILES['file']['name']);
    try {
        $fileName = $_FILES['file']['name'];
        $resizeObj = new resize('photos/' . $fileName);

// *** Resize options: exact, portrait, landscape, auto, crop
        $resizeObj->resizeImage(225, 150, 'auto');
        $extension = strtolower(strrchr($fileName, '.')); // extract file extension
        $clean = str_replace($extension, '', $fileName); // replace file extension with nothing -> removes

        $resizeObj->saveImage('photos/' . $clean . '.png', 100);
        unlink('photos/' . $fileName);
    } catch (Exception $e) {
        echo 'Error ' . $e->getMessage() . "\n";
    }

I have tried parsing the $_FILES['file']['name'] directly into the resize class but this does do anything, hence i save the original -> modify the size -> strip the extension -> save as png -> delet original

Any input is greatly appreciated.

Squidge

Squidge 101 Newbie Poster

Dear davidjennings

Your code is a miss mash of different coding technics.

You are using the MySQLi connection method but as MySQL.

For example:

MySQL

$con = mysql_connect('host','user','password'); <-- Notice no database selected

http://php.net/manual/en/function.mysql-connect.php

Where as your line 2 of code snippet 2 shows this:

$conn = mysql_connect("localhost","user_david","password","djenning_databaseclass"); **<-- You cannot select a database during MySQL connect**

MySQLi

$con = mysqli_connect('host','user','password','database');

http://www.php.net/manual/en/mysqli.construct.php

Sp you must decide which you are going to be using. As you have stated you want to use OOP.

If this is the case you can use MySQLi, or as I have already mentioned PDO with MySQL.

Squidge 101 Newbie Poster

I use percentage as this allows for more flexibility and fluidness for cross browser/platform.

For text i use èm

Squidge 101 Newbie Poster

Thanks, I am trying to write functions and some OOP. How would I do this using OOP.

MySQL is not capable of OOP, either use MySQLi or MySQL with a PDO wrapper

Squidge 101 Newbie Poster

This is a very simple script to display files (check array for valid extensions) from a set folder:

$dir = 'photos/';

// Array of excepted data types
$file_display = array('jpg', 'jpeg', 'png', 'gif');    

if(file_exists($dir) == false){
    echo 'Directory \''.$dir.'\' not found!';
}  else {
    $dir_content = scandir($dir);

    foreach ($dir_content as $file){
        $file_type = strtolower(end(explode('.', $file)));

        if($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == TRUE){
            echo $file.'<br/><br/><img src="'.$dir.'/'.$file.'" alt="'.$file.'"/><br/>';

        }

    }
}
Squidge 101 Newbie Poster

Have you created the folder:
$imgdir = "../blob/uploads/"; this will make this folder one level back from where your script is.

I would suggest for testing only, have the script in tyhe root of your site, and the folder on the above line renamed to uploads/ and create the folder from your root.

Squidge 101 Newbie Poster

post your code

Squidge 101 Newbie Poster

Is this using ZF?

Squidge 101 Newbie Poster

I have to agree.

Are you asking a question?

If you are unsure on how to ask a well formed question, please refer to the link in my sig.

Thank you for your understanding.

Squidge 101 Newbie Poster

hahaha many thanks to both.

@TonyG,

Wolud this need the thumb image to be a button?

@Lukas,

Thanks for the link, will have a look through that.

Squidge 101 Newbie Poster

Hi All,

I am creating an "About Us" portfolio page for a company. On this page will be a small bio and a photo.

The bio is not a problem, uploading and storing/calling the image is not a problem, as i already have code i can reuse.

The part i am struggerling to get my head around, as just cant seem to imagine the functions, is how to choose/select a photo to link to the bio from what is available in a "photo" folder on the server.

Images would need to be changable -> this would be from an Admin section.

I am not after code, just a kinda flow process.

Thanks in advance.

Squidge 101 Newbie Poster
Squidge 101 Newbie Poster

reformed smoker. Used to smoke 20~30, unless i was drinking and it nearly doubled :(

Squidge 101 Newbie Poster

Deffinatley agree with AHarris.

User would need to use a "Forgot Password (I'm stupid) Link", where user name or email is used to validate against.

This then creates a random token string whcih is emailed as part of a URL where the user is then forced to reset password.

Squidge 101 Newbie Poster

Maybe you do not have short hand PHP tag enabled.

Above line 42:

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

Change to :

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

Although, if you are new and starting fresh code, i would suggest you drop the MYSQL syntax usage and opt for either PDO with MySQL, or MySQLi.

Squidge 101 Newbie Poster

This is one i found for generating 1 time/use URLS:

http://phpmaster.com/generating-one-time-use-urls/

All kudos to PHP Master on this one

Squidge 101 Newbie Poster

Also what do you have the "content" field set as?

for example : VARCHAR, CHAR, DATE etc

Squidge 101 Newbie Poster

ok many thanks Dani. I will have a look over my phone.

Look forward to the app. do you have an ETA as yet?

Squidge 101 Newbie Poster

Afternoon all.

I have noticed recently that i am unable to log in to DaniWeb from Android Mobile.

When selecting the "Member Login" the pop out box appears then disappears before i can do anything.

Could this be looked at? Or has DaniWeb got a mobile app?

Squidge 101 Newbie Poster

php.net

Squidge 101 Newbie Poster

Did you read the post ^^

session_start() has to be the first out put, even before your DOCTYPE decleration.

Amend that first::

Squidge 101 Newbie Poster

http://php.net/manual/en/function.session-start.php

Note:
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

Squidge 101 Newbie Poster

session_start() needs to be the first thing.

Shift your PHP above the HTML doctype

Squidge 101 Newbie Poster

@masterjiraya,

Your welcome. :)

Squidge 101 Newbie Poster

It maybe over kill but i use salt and SHA1

I use this to create a random 50 character string:

private function randomString($length = 50) // Produces random string of $lenght
    {
        $rdString = "";

        $possible = '12346789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // Available characters for string

        $mxlength = strlen($possible);

        if ($length > $mxlength) {
          $length = $mxlength;
        }

        $i = 0; 

        while ($i < $length) { 
          $char = substr($possible, mt_rand(0, $mxlength-1), 1);

          if (!strstr($rdString, $char)) { 
            $rdString .= $char;
            $i++;
          }
        }
        return $rdString;
    }

Then use $rdstring with users password and sha1:

public function BLAHBLAH($password){
    //Generate user salt
    $user_salt = $this->randomString();

    $encPassword = sha1($password . $user_salt);

    return $encPassword;
}
Squidge 101 Newbie Poster
Squidge 101 Newbie Poster

I googled and googled to try and find a comprehensive wiki/tut on how to share htdocs across a dual platform.

My base install is Windows 7 64bit, and recently (6wks ago) set up a dual boot.
One thing pained me for a while of not being able to use the current edited files from one system to the other.

So for anyone that is looking to do this, I finally sussed it and have it working :).

Assumptions:
1. You have XAMPP installed on Windws platform
2. You have XAMPP installed on Linux platform
3. You know how to access Terminal in Linux

All text ->

Like this is in terminal

So, first things first we need to modify the way Linux mounts the additional drives/partitions.

Firstly unmount the Windows drive.

This is done using the fstab file. So before we make changes make a back up.

sudo cp /etc/fstab /etc/fstab_orig

We also need to get the UUID of our other drive (Windows drive) using blkid:

sudo blkid
/dev/sda1: LABEL="SYSTEM" UUID="9EC0347FC0346027" TYPE="ntfs" 
/dev/sda2: LABEL="OS" UUID="E868357B68354998" TYPE="ntfs" 
/dev/sdb1: UUID="4659932c-47e6-431b-8bda-779a3e2efb18" TYPE="ext4" 
/dev/sdb5: UUID="8170f6c2-aa22-4b9b-9480-8231665ff232" TYPE="swap" 
/dev/sdb6: UUID="783cc8a0-24c3-44cd-9c61-01d51d047099" TYPE="ext4" 
/dev/sdb7: UUID="26a38c59-f39c-47eb-b9aa-b15f4355951f" TYPE="ext4" 
/dev/sr0: LABEL="Disk1" TYPE="udf" 
/dev/sdc1: LABEL="WebDesign" UUID="18C47AFBC47ADB08" TYPE="ntfs" 

This will give you output of the UUIDs in use matching the HDDs. Make a note of the long alphanumeric UUID that corresponds to your Windows drive. Then using the editor of your choice (Iam using gedit in this), we are going to tag a line on the very end

pritaeas commented: Nice one. +14
diafol commented: Nice to know +14
cereal commented: thanks for sharing! +11
LastMitch commented: Nice Work! +11
Squidge 101 Newbie Poster

Will do, thanks :)

Squidge 101 Newbie Poster

Hi All,

Not sure really where this should go but.....

I have recently setup a shared HTDOCS under XAMPP across a dual boot system (Win7 & Ubuntu).

Not sure if there is an interest, but if anyone would like to know how to do it, please give me a shout and i can post up how i did it

Squidge 101 Newbie Poster

As it is encrypted not sure what you expect anyone to do.

Have you contacted FileShareScript?

Have you got the IONCUBE installed?

Squidge 101 Newbie Poster

Whats in your config.php

As Diafol has mentioned the error is in there

Squidge 101 Newbie Poster

Where are you getting $Geneprocess from?

Squidge 101 Newbie Poster

No probs fellow, we all start somewhere.

With videos/pictures i personnally wouldnt store the vid in the SQL table (some do, some dont).

I would store the name, and link to the video only. This reduces the call time and also the size of your table.

Squidge 101 Newbie Poster

This is just the SQL code for the table.

You need to add an additional column for example bday DATE NOT NULL,

Change bday to what you want it to be called

Squidge 101 Newbie Poster

I gotta be the dumbest poster on this site... wrong title + wrong forum.

Please mark this solved

Squidge 101 Newbie Poster

Post in the correct forum?

This is PHP

Squidge 101 Newbie Poster

@LastMitch,

Thats the link i couldnt find :)

+1

Squidge 101 Newbie Poster

What is your test platform?

I use XAMPP

http://www.apachefriends.org/en/xampp.html

  • Apache 2.4.3
  • MySQL 5.5.27
  • PHP 5.4.7
  • phpMyAdmin 3.5.2.2

Then use either GIT or PEAR

EDIT Although installing Apache & MySQL as services fails currently under the new GUI

Squidge 101 Newbie Poster

@kakalahori

You need to install the PHPUnit module. This can be easily done via PEAR

http://pear.php.net/manual/en/installation.getting.php

Or via GIT

https://github.com/sebastianbergmann/phpunit/

I used PEAR in my set up as it also allows access to the pre compiled libraries.

Squidge 101 Newbie Poster

Line 11 => $result2, but you then use $result in line 15 & 24
Line 13 => You check where against both username and passwd, but you only get POST data for username.

Other than that i have not used "Swift_Mailer" before, so maybe someone can shed some light, or have you reviewed the HOWTO where the class was downloaded from?

Squidge 101 Newbie Poster

Please format your code block correctly using the code or inline code

Squidge 101 Newbie Poster

From what i understood OOP is not com[patible with MySQL. You will need to use MySQLi or PDO wrapper.

Your increment is in the wrong place, this should be after doing X and looping, for example:

$i=1;
while($i<=5){
  echo "The number is " . $i . "<br>";
  $i++; #<-- increment at the end
}

You also have to many () in your while statement:

while((($rows=mysql_fetch_row($result))>$num    )){

This should be:

while(($rows=mysql_fetch_row($result))>$num){

In addition, at the end of your loop you are setting it back to 0:

if ($num == $max){
echo "</tr>";
$num = 0;#<------- RESETTING THE LOOP COUNTER
} 

You have a variable $row[pic] on line 21, i am guessing this is ment to be $rows[pic]

Squidge 101 Newbie Poster

ZF2 is no longer using zf.bat.

If you look over the base tutorial it takes you through how to install:

cd /my-project/dir
git clone git://github.com/zendframework/ZendSkeletonApplication.git
cd ZendSkeletonApplication
php composer.phar self-update
php composer.phar install

This obviously assumes you have composer, and git installed.

Here is a sample tut: http://bigemployee.com/zend-framework-2-simple-web-application-crud-using-ajax-tutorial/ that the above was taken from.

I am looking through ZF2 at the present (and also ZF1), do be careful on the ZF2 tut on the ZF2 website, as there are errors.

I have just gone through this a few times and installed onto Win 7 64Bit within 5 minutes.

Make sure you allow git to amend your PATH, and also ensure you manually add the composer PATH variable

Squidge 101 Newbie Poster

Ok, i feel stupid.

I had:

protected function __initDoctype()
    {
        $this->bootstrap('view');

SHould be:

protected function _initDoctype()
    {
        $this->bootstrap('view');

Note the single _.

@LastMitch,

The link you put unfortunatley is relating to ZF2, i havent ventured on to that as yet.

But thank you for your input. I have seen HELPERS in ZF1 but not got to those, as i am going through a few tutorials and piecing bits together.

LastMitch commented: Nice Catch! +11
Squidge 101 Newbie Poster

Hi LastMitch,

I tried

    <?php echo $doctype = $view->doctype()->getDoctype(); ?>

but got errors stating :

Notice: Undefined variable: view in C:\xampp\htdocs\thenextsocial\application\layouts\scripts\layout.phtml on line 1

Fatal error: Call to a member function doctype() on a non-object in C:\xampp\htdocs\thenextsocial\application\layouts\scripts\layout.phtml on line 1

Where is the doctypeHelper added? Is this to the Bootstrap function __initDoctype()?

Squidge 101 Newbie Poster

@LastMitch,

I have doctype() echo'd:

<?php echo $this->doctype(); ?>
<html>
    <head>

This is the first 3 lines of the layout.phtml