codeigniter


access folder outside code igniter


I've been to trying to upload images using code igniter and it works perfectly when the upload folder is just outside of application folder. But my problem is when I try to access folder which is outside whole code igniter folder it is throwing me a error. How to access the folder outside the code igniter folder? I tried $_SERVER['DOCUMENT_ROOT']. But it dint help.
$name = $_POST['name'];
$id = $_POST['id'];
if (isset($_FILES['upload']['name'])) {
// total files //
$count = count($_FILES['upload']['name']);
// all uploads //
$uploads = $_FILES['upload'];
for ($i = 0; $i < $count; $i++) {
if ($uploads['error'][$i] == 0) {
$firstimage = $uploads['name'][$i];
$secondimage = $uploads['name'][$i];
move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]);
$config2['image_library'] = 'gd2';
$config2['source_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i];
$config2['new_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/thumbnail/'.$uploads['name'][$i];
$config2['maintain_ratio'] = FALSE;
$config2['create_thumb'] = TRUE;
$config2['thumb_marker'] = '_thumb';
$config2['width'] = 75;
$config2['height'] = 50;
$config2['overwrite'] = TRUE;
$this->image_lib->initialize($config2);
$this->load->library('image_lib',$config2);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
$config3['image_library'] = 'gd2';
$config3['source_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i];
$config3['new_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/resize/'.$uploads['name'][$i];
$config3['maintain_ratio'] = FALSE;
$config3['create_thumb'] = TRUE;
$config3['thumb_marker'] = '_thumb';
$config3['width'] = 470;
$config3['height'] = 470;
$config3['overwrite'] = TRUE;
$this->image_lib->initialize($config3);
$this->load->library('image_lib',$config3);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
}
}
$this->load->view('head');
$data = array(
'name' => $name,
'id' => $id
);
After discussing in comments, the problem is likely the move_uploaded_file() function is trying to move the file to a directory that doesn't exist yet.
move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]);
Before the file can be moved the folder needs to be created. If $id is new, it has probably not been created yet. So...
if (!is_dir($_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id)) {
mkdir($_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id);
}
move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]);

Related Links

Create pdf having each page background in different color using DOMPDF
image not storing in folder using codeigniter
Dynamically inserted textbox values to be stored in a variable
using mysqli driver in ci
Send sms using twilio and codeigniter
$_FILES['imagem'] is undefined in Firefox
CodeIgniter accessing models from helper
How to reuse form in codeigniter for update and add
How enable mbstring in codeigniter
make looping insert database from codeigniter
CodeIgniter URL: web.com/user/register/step/1
How can give name for generate pdf using mpdf codeigniter
php error: The Encrypt library requires the Mcrypt extension in codeigniter
how to join tables of two different databases
how to validate error in specific element or fields - Codeigniter
Integrate solr with codeigniter

Categories

HOME
amazon-s3
vb.net
hadoop
copy
rtmp
amazon-kinesis
prometheus
geany
jbpm
jena
stm
wso2-das
avplayer
oracle-agile-plm
accumulo
data-annotations
atmelstudio
procedure
co
deadbolt
aikau
ssms-2014
confidence-interval
unsigned-integer
rrd
number-formatting
meanjs
asp.net-identity-2
apscheduler
opensuse
popupwindow
stl
skyscanner
mobilefirst-bluemix
nio
docker-image
ecdsa
angular-xeditable
uistoryboardsegue
linechart
otroslogviewer
drupal-webform
windows-scripting
atlassian-bitbucketserver
h5py
spark-submit
sdcc
nscalendar
sql-insert
koala-framework
javascript-security
haste
untagged
autogen
glumpy
qtcpserver
waf
sqlite-net
proc
amazon-dynamodb-streams
data-fitting
rsh
sql-server-2016-express
qlpreviewcontroller
duration
isapi-rewrite
jongo
jca
tag-helpers
multer
database-tuning-advisor
phone-number
oboe.js
heroku-toolbelt
voting
julian
dhc
gevent-socketio
data-science-studio
fastparse
openxls
adserver
mysql5
computer-science-theory
concurrentdictionary
private-methods
bunny
spread-toolkit
pydatalog
sshj
re2c
libnids
capitalize
asp.net-authentication
northwind
dependency-walker
12factor
haar-wavelet
xsocket
oncreate
libavg
ria
molehill
ondraw
f2c
bubble-popup
excel-web-query
markitup
resharper-4.5
shareware
docking

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App