I have created a script that will upload files to a general uploads folder, the upload works fine however when I try to get the script to move the files from the temp folder to the uploads folder. I get the following issue.
[23-Mar-2012 18:57:21 UTC] PHP Warning: move_uploaded_file(): Unable to move '/var/tmp/php3O42Kn' to '/home3/***/***/***/MAINFOLDER/uploads/itworks/' in /home3/***/***/***/MAINFOLDER/admin/uploader.php on line 21
When I had the uploads folder in the same directory as the uploader.php script it was working, however I placed my uploader.php script in the /admin folder while keeping the /uploads in the root folder. Below is the script I am using.
uploader.php (main/admin)
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $filename;
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
if (!file_exists($targetPath)) {
mkdir(str_replace('//','/',$targetPath), 0755, true);
}
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
// } else {
// echo 'Invalid file type.';
// }
}
?>
upload.php (main/admin)
<script type="text/javascript">
$(document).ready(function() {
$("#file_upload").uploadify({
'uploader' : 'includes/uploadify.swf',
'script' : 'uploadify.php',
'folder' : '../uploads',
'cancelImg' : 'includes/images/cancel.png',
'multi' : true,
'auto' : false,
'fileTypeExts' : '*.jpg;*.gif;*.png',
'fileTypeDesc' : 'Image Files (.JPG, .GIF, .PNG)',
'queueID' : 'custom-queue',
'queueSizeLimit' : 10,
'simUploadLimit' : 3,
'sizeLimit' : 10240000,
'removeCompleted': true,
'onAllComplete' : function(stats) {
$('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.');
}
});
});
</script>
I think the issue is here: 'folder' : '../uploads',. Idealy I want the uploader.php file to automatically push the directory back one level however all my methods seem not to have worked.
Many thanks to anyone who could help me shed some light on this!
It could be one of the following depending on how far root is from the current admin directory.
or