Jump to content

Image Upload No Longer Works


dachshund

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.