/    Sign up×
Community /Pin to ProfileBookmark

Help adding another file-type

I’m using the PHPmotion script ([url]http://demo.phpmotiontemplates.com/default/[/url])
and I’m attempting to add another file-type for uploading (.pdf), currently it’s just png, jpg and gif.
I’m simply looking for a little guidance on what to add, to this code, to add a pdf file-type.
I’m guessing that this may be the area (from the attached file) that needs some pdf coding:

[CODE]// lets keep same image types
if( $img_file_type[$x] == “image/pjpeg” || $img_file_type[$x] == “image/jpeg” ) {
$new_img = imagecreatefromjpeg($img_file_tmp[$x]);
}
elseif( $img_file_type[$x] == “image/x-png” || $img_file_type[$x] == “image/png” ) {
$new_img = imagecreatefrompng($img_file_tmp[$x]);
}
elseif( $img_file_type[$x] == “image/gif” ) {
$new_img = imagecreatefromgif($img_file_tmp[$x]);
}

list($width, $height) = getimagesize($img_file_tmp[$x]);[/CODE]

Any help will be greatly appreciated.

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowSep 23.2014 — Well, PDF isn't an image so what that's doing really had no business even being touched by that code... you'd need to short-circuit out and write a whole different handler for that.

Though that code you shared is filled with endless "FOR WHAT" and disastrously outdated... like the variables for nothing, use of the deprecated and soon to no longer exist mysql_ functions [url=http://php.net/manual/en/function.mysql-connect.php](hence the giant red warning box in the manual)[/url], presence of tags like FONT that has no business in any markup written after 1997... even the part you shared says "I don't know enough PHP to be writing PHP" since if you are checking the same value over and over it's more efficient to use SWITCH/CASE than it is "else if".

switch ($img_file_type[$x]) {
case 'image/pjpeg':
case 'image/jpeg':
$new_img = imagecreatefromjpeg($img_file_tmp[$x]);
break;
case 'image/x-png':
case 'image/png':
$new_img = imagecreatefrompng($img_file_tmp[$x]);
break;
case 'image/gif':
$new_img = imagecreatefromgif($img_file_tmp[$x]);
}


Which should probably be done AFTER the image size information check so it's not wasting time and memory creating a bitmap that's just going to be thrown away. Even this:

$img_uploaded = sizeof($img_file_tmp);

<i> </i> for ( $x=0; $x &lt; $img_uploaded; $x++ ) {
<i> </i> if ( $img_file_tmp[$x] != '' ) $img_file_tmp_count++;
<i> </i> }

<i> </i> if ( $img_file_tmp_count == 0 ) $img_file_tmp_count=1;

<i> </i> $count_bad = 0;

<i> </i> for ( $x=0; $x &lt; $img_file_tmp_count; $x++ ) {


Is pointless code bloat for Christmas only knows what. (though I suspect we're talking is_array's job)

In any case though, since PDF isn't an image file format, you'd need to detect it WAY [b]WAY[/b] sooner in the code and write a whole separate handler for it.
×

Success!

Help @chrisjchrisj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...