dachshund Posted November 18, 2010 Share Posted November 18, 2010 I'm sure there is a very simple fix to this problem. I have an image uploader in the backend of my site. Since moving hosts this no longer works. The PHP is if((!empty($_FILES["indeximage"]))) { $indeximagename = basename($_FILES['indeximage']['name']); $indeximagenew = $_SERVER['DOCUMENT_ROOT'] . '/images/uploaded/index/' . $indeximagename; if (!file_exists($indeximagenew)) { if ((move_uploaded_file($_FILES['indeximage']['tmp_name'], $indeximagenew)) === true) { echo $indeximagename; echo ' was successfully uploaded.'; }else { echo 'Unable to move'; echo $indeximagename; echo ' into the right folder.'; } }else { echo 'You did not upload an index image.'; } } I'm guessing the problem is with the document root part. $indeximagenew echos /var/www/vhosts/webaddress.co.uk/httpdocs/images/uploaded/index/imagename.jpg The actual actual address of the image, when on the site, is http://www.webaddress.co.uk/images/uploaded/index/imagename.jpg Any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2010 Share Posted November 18, 2010 You (your browser) accesses images on web pages using their URL. Php accesses files on the server using the file system path. Those two things are not the same. $_SERVER['DOCUMENT_ROOT'] is the file system path to your document_root folder (if it is setup correctly) and only has meaning to php's functions that act on files on the server. To get help with what your code is doing or not going, you would need to describe the symptom you see in front of you when you try it. Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136042 Share on other sites More sharing options...
dachshund Posted November 18, 2010 Author Share Posted November 18, 2010 Thanks, it echos back "Unable to move into the right folder". Do you know what I need to do to select the correct destination? Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136049 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2010 Share Posted November 18, 2010 Add the following two lines of code after the line with your first opening <?php tag to get php to report and display all the errors it detects - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136053 Share on other sites More sharing options...
dachshund Posted November 18, 2010 Author Share Posted November 18, 2010 before I click upload it says Notice: Undefined index: images in /var/www/vhosts/webaddress.co.uk/httpdocs/admin/images.php on line 58 Notice: Undefined index: indeximage in /var/www/vhosts/webaddress.co.uk/httpdocs/admin/images.php after upload (which doesn't work obviously) it says Notice: Undefined index: images in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 58 Warning: move_uploaded_file(../images/uploaded/index/yangli.jpg): failed to open stream: Permission denied in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 Warning: move_uploaded_file(): Unable to move '/tmp/phpIzemjy' to '../images/uploaded/index/yangli.jpg' in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 Unable to move Index Image into the right foler. Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136094 Share on other sites More sharing options...
dachshund Posted November 18, 2010 Author Share Posted November 18, 2010 Anyone know what I can do to fix it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136153 Share on other sites More sharing options...
BlueSkyIS Posted November 18, 2010 Share Posted November 18, 2010 Warning: move_uploaded_file(../images/uploaded/index/yangli.jpg): failed to open stream: Permission denied in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 failed to open stream: Permission denied in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 failed to open stream: Permission denied Permission denied is the target directory writable by the web server? chmod 777 Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136158 Share on other sites More sharing options...
dachshund Posted November 18, 2010 Author Share Posted November 18, 2010 yep they're all fully writable. it used to work perfectly until i changed web server. now the address includes httpdocs. any more help would be fantastic. Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136374 Share on other sites More sharing options...
dachshund Posted November 19, 2010 Author Share Posted November 19, 2010 I would love to get this fixed ASAP, so if anyone wants more info or has any ideas please let me know! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/219061-image-upload-no-longer-works/#findComment-1136403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.