I am having a serious problem with having the image that is uploaded being moved to another directory.
The file that is being called to handle the upload is located in one directory while i want the image moved to another however in my code if set the dest variable to another directory then it won't, but if i leave it to the current directory then everything is fine.
Any advice would be helpful.
below is the class that handles everything.
class Inventory {
var $imgSource = '';
var $name = '';
var $path = '';
var $isError = false;
var $errorMsgs = array();
var $properties = array();
var $successMsg = '';
var $_maxImageSize = '';
var $_imageSize = '';
var $_imageFileSize = '';
var $_imageWidth = '';
var $_imageHeight = '';
var $_maxImageWidth = '';
var $_maxImageHeight = '';
var $_partName = '';
var $_partLabel = '';
var $_partCaption = '';
var $_db = '';
var $_partPrice = '';
function Inventory() {
$this->path = '/images/';
$this->imgSource = htmlentities($_FILES['partImage']['tmp_name']);
$this->name = $_FILES['partImage']['name'];
$this->dest = $this->path.$this->name;
$this->_partPrice = $_REQUEST['partPrice'];
$this->_validate();
if ($this->isError) {
$this->_clearAllVars();
unlink($_FILES['partImage']['tmp_name']);
return false;
}
$this->_setProperties();
$this->_dbHandle();
$this->_db->dbcnx();
$sql = "INSERT INTO parts ";
$sql .= "(part_id, name, caption, price, status, imageName) ";
$sql .= "VALUES ";
$sql .= "('', '$this->_partName', '$this->_partCaption', '$this->_partPrice', '0', '$this->dest')";
$this->_db->query($sql);
if ($this->_db->data_affected_rows() < 1) {
$this->errorMsgs[] = array (
'Error Name' => 'Failed Database Insert',
'Error Message' => 'An Error Occurred Adding the product to the database'
);
$this->isError = true;
return false;
}
if (move_uploaded_file($this->imgSource, $this->dest)) {
print 'cool';
$this->_clearAllVars();
exit;
} else {
$this->errorMsgs[] = array (
'Error Name' => 'Upload Error',
'Error Message' => 'The file was unable to be uploaded. Please contact the webmaster'
);
$this->isError = true;
return false;
}//end else
return true;
}//end addImage()
function successMessage($msg) {
$this->successMsg = $msg;
return $this->successMsg;
}//end printSuccessMessage()
function _isImageValid() {
$this->imgSource = $_FILES['partImage']['tmp_name'];
$this->_imageSize = getimagesize($this->imgSource);
$this->_imageWidth = $this->_imageSize[0];
$this->_imageHeight = $this->_imageSize[1];
$this->_maxImageSize = 200000;
$this->_imageFileSize = $_FILES['partImage']['size'];
$this->_maxImageWidth = 640;
$this->_maxImageHeight = 480;
if ($this->_maxImageWidth < $this->_imageWidth ||
$this->_maxImageHeight < $this->_imageHeight) {
$this->errorMsgs[] = array (
'Error Name' => 'Wrong Image Dimensions',
'Error Message' => 'The image submitted must be no greater than 640x480'
);
$this->isError = true;
return false;
}//end if
if (empty($this->imgSource)) {
$this->errorMsgs[] = array (
'Error Name' => 'Image File Error',
'Error Message' => 'To submit the form without selecting an image'
);
$this->isError = true;
return false;
}//end if
if ($this->_imageFileSize > $this->_maxImageSize) {
$this->errorMsgs[] = array (
'Error Name' => 'File Size',
'Error Message' => 'The file you submitted was to large. Max size is 2megs'
);
$this->isError = true;
return false;
}//end if
return true;
}//end isImageValid()
function _checkForBlankEntries() {
$this->_partName = $_REQUEST['partName'];
$this->_partPrice = $_REQUEST['partPrice'];
$this->_partCaption = $_REQUEST['partCaption'];
if (empty($this->_partName)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Name Field',
'Error Message' => 'Please make sure that you filled in the part name'
);
$this->isError = true;
return false;
} elseif (empty($this->_partPrice)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Price Field',
'Error Message' => 'Please enter a price for the part'
);
$this->isError = true;
return false;
} elseif (empty($this->_partCaption)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Caption Field',
'Error Message' => 'Please enter a caption for the part'
);
$this->isError = true;
return false;
}//end if
return true;
}//end _checkForBlankEntries()
function _validate() {
$this->imgSource = $_FILES['partImage']['tmp_name'];
$this->_partName = $_REQUEST['partName'];
$this->_partPrice = $_REQUEST['partPrice'];
$this->_partCaption = $_REQUEST['partCaption'];
$this->_imageSize = getimagesize($this->imgSource);
$this->_imageWidth = $this->_imageSize[0];
$this->_imageHeight = $this->_imageSize[1];
$this->_maxImageSize = 200000;
$this->_imageFileSize = $_FILES['partImage']['size'];
$this->_maxImageWidth = 640;
$this->_maxImageHeight = 480;
if ($this->_maxImageWidth < $this->_imageWidth ||
$this->_maxImageHeight < $this->_imageHeight) {
$this->errorMsgs[] = array (
'Error Name' => 'Wrong Image Dimensions',
'Error Message' => 'The image submitted must be no greater than 640x480'
);
$this->isError = true;
return false;
}//end if
if (empty($this->imgSource)) {
$this->errorMsgs[] = array (
'Error Name' => 'Image File Error',
'Error Message' => 'To submit the form without selecting an image'
);
$this->isError = true;
return false;
}//end if
if ($this->_imageFileSize > $this->_maxImageSize) {
$this->errorMsgs[] = array (
'Error Name' => 'File Size',
'Error Message' => 'The file you submitted was to large. Max size is 2megs'
);
$this->isError = true;
return false;
}//end if
if (empty($this->_partName)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Name Field',
'Error Message' => 'Please make sure that you filled in the part name'
);
$this->isError = true;
return false;
} elseif (empty($this->_partPrice)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Price Field',
'Error Message' => 'Please enter a price for the part'
);
$this->isError = true;
return false;
} elseif (empty($this->_partCaption)) {
$this->errorMsgs[] = array (
'Error Name' => 'Empty Caption Field',
'Error Message' => 'Please enter a caption for the part'
);
$this->isError = true;
return false;
}//end if
return true;
}//end _validate()
#added function to common.inc
function _setProperties() {
$this->_partPrice = htmlentities(trim($this->_partPrice));
$this->_partName = htmlentities(trim(ucfirst($this->_partName)));
$this->_partCaption = htmlentities(trim($this->_partCaption));
return true;
}//end _formatVars()
function _clearAllVars() {
$_REQUEST = array();
unset($_REQUEST);
}//end _clearAll
function _dbHandle() {
if (!is_object($this->_db)) {
$this->_db = new mysql_db;
return $this->_db;
}
}//end _dbHandle()
}//end partAdmin class
Here is the error that get from php along with the dump
//
<b>Warning</b>: move_uploaded_file(/images/AX001089.jpg): failed to open stream: No such file or directory in <b>/usr/home/web/users/a0020784/html/admin/lib/base.php</b> on line <b>67</b><br />
<br />
<b>Warning</b>: move_uploaded_file(): Unable to move '/var/tmp/phpu7KuRg' to '/images/AX001089.jpg' in <b>/usr/home/web/users/a0020784/html/admin/lib/base.php</b> on line <b>67</b><br />
inventory Object
(
[imgSource] => /var/tmp/phpu7KuRg
[name] => AX001089.jpg
[path] => /images/
[isError] => 1
[errorMsgs] => Array
(
[0] => Array
(
[Error Name] => Upload Error
[Error Message] => The file was unable to be uploaded. Please contact the webmaster
)
)
[properties] => Array
(
)
[successMsg] =>
[_maxImageSize] => 200000
[_imageSize] => Array
(
[0] => 293
[1] => 264
[2] => 2
[3] => width="293" height="264"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
[_imageFileSize] => 13897
[_imageWidth] => 293
[_imageHeight] => 264
[_maxImageWidth] => 640
[_maxImageHeight] => 480
[_partName] => Adsfasdf
[_partLabel] =>
[_partCaption] => asdfasdfasdf
[_partPrice] => 23445
[dest] => /images/AX001089.jpg
)