Using a PHP in Pages plugin, I have been embedding my PHP files in WordPress Pages and calling them via short code.
The following code runs fine by itself. However, when I paste it into a WordPress page, it doesn't do anything. All my other PHP files work fine.
Can anyone tell me what the possible problems are?
---------------------------------------------------------------------
<?php
session_start();
//handle form submission
if($_POST){
//handle file upload
// Edit upload location here
$destination_path = "/gallery/images/";
$rand_str = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
$target_path = $destination_path . $rand_str . "_" . basename( $_FILES['image']['name']);
$filename = $rand_str . "_" . basename( $_FILES['image']['name']);
if (pathinfo($filename,PATHINFO_EXTENSION)!=='jpg' && pathinfo($filename,PATHINFO_EXTENSION)!=='jpeg' && pathinfo($filename,PATHINFO_EXTENSION)!=='gif' && pathinfo($filename,PATHINFO_EXTENSION)!=='png' && pathinfo($filename,PATHINFO_EXTENSION)!=='JPG' && pathinfo($filename,PATHINFO_EXTENSION)!=='JPEG' && pathinfo($filename,PATHINFO_EXTENSION)!=='GIF' && pathinfo($filename,PATHINFO_EXTENSION)!=='PNG') {
echo "Not valid image file.";
}
elseif(@move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
echo "File uploaded and added to selected categories.";
//which categories are we adding the file to?
$cats="";
$result=mysql_query("select * from categories where parent_category='2' ") or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
$cats .= $row['id'].", ";
}
//do we also add it to categories under parent category 1?
if($_POST['cat1too']==1){
$result=mysql_query("select * from categories where parent_category='1' ") or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
$cats .= $row['id'].", ";
}
}
mysql_query("insert into object_dir (content,category) values ('$target_path','$cats') ") or die(mysql_error());
}
// Close Session
mysql_close();
}
?>
[please review the forum guidelines for posting code - http://codex.wordpress.org/Forum_Welcome#Posting_Code ]
---------------------------------------------------------------------
Thanks,
---
Wordpress. Some Assembly Required.