Using exec() to get md5sum of a file, having a problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grdlock
Forum Newbie
Posts: 1
Joined: Thu Apr 01, 2010 11:24 am

Using exec() to get md5sum of a file, having a problem...

Post by grdlock »

First, I don't know PHP very well at all.

I have a page where people upload files through PHP, information about the person who uploaded the files and file description is stored in a file when they upload.

Basically, I want to have the md5sum of the file stored in that description as well so I can pull it when the files are listed.

Code: Select all

$md5file = "$current_dir/$filename";
$md5temp = exec('md5sum '.$md5file);
The problem is that most of the directories contain spaces. So it's executing the command "md5sum files\my files\file.zip" when it needs to be "md5sum files\my/ files\file.zip" since it's a linux system. I don't know how to check for any spaces that may be in $current_dir or $filename and change them to "/ " so that the command will execute correctly.

My second question is once I get the md5sum, it will be "32 characters files\my files\file.zip" .... how can I only extract the first 32 characters so I just get the actual md5sum, instead of the md5sum and directory/file that will be in the output?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Using exec() to get md5sum of a file, having a problem..

Post by Benjamin »

I believe you can put the file path in single quotes.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Using exec() to get md5sum of a file, having a problem..

Post by AbraCadaver »

Why not:

Code: Select all

$md5temp = md5_file($md5file);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply