Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-16-2002, 08:45 PM   PM User | #1
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
can't upload image problem

Hi all.
I have tried and tried to fix this but as I'm a newbie I'm having no luck. Got this setup/script made for us - paid a small amount - but am having this one problem.

When I add a product we are supposed to browse for image which it uploads but just the path/image name is stored in database.

The error I get is:
Warning: Unable to create '/var/www/images/uploads/coaster.jpg': No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 316

Warning: Unable to move '/tmp/phpMaCLxK' to '/var/www/images/uploads/coaster.jpg' in /home/holidays/public_html/admin/addproduct.php on line 316
product added successfully

The code for connect.php (which includes the path) is:-

<?
define('UploadDir', $_SERVER['DOCUMENT_ROOT'] . '/images/uploads/' ); // replace /familytravel/images/upload with the path to your upload directory.
define('DBUploadDir', '/images/uploads/'); // replace /familytravel/images/upload with the path to your upload directory. this will be used in URLS
$cnx = @mysql_connect('localhost', 'user', 'password');
if(!$cnx) {
echo('Failed to log into database at this time');
}

$select = mysql_select_db('holidays_dest');
if(!$cnx){
echo('failed to select database');
}

function dateSplit($date)
{
//$splitdate[0] = year
//$splitdate[1] = month
//splitdate[2] = day
$splitdate = explode("-", $date);
return $splitdate;
}
?>

The line 316 of addproduct.php referred to in the error message is:-

move_uploaded_file($_FILES['files']['tmp_name'], UploadDir . $_FILES['files']['name']);

I have changed the path about a million times and the code for connect.php is what should apparantly work but doesn't.

Thanking you for any help, Sheryll.

Last edited by sticks; 10-17-2002 at 08:27 PM..
sticks is offline   Reply With Quote
Old 10-16-2002, 09:27 PM   PM User | #2
Galdo
New Coder

 
Join Date: Aug 2002
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Galdo is an unknown quantity at this point
Is the directory set up with the right write permissions?
Galdo is offline   Reply With Quote
Old 10-17-2002, 07:54 AM   PM User | #3
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi.
It is set up with 777 which apparantly is correct - although I'm new)

Thanks, Sheryll.
sticks is offline   Reply With Quote
Old 10-17-2002, 01:18 PM   PM User | #4
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
The first thing you want to do is edit your first post and remove the database access password - not good form to be posting that in a public forum.

Assuming the directory /uploads/ is in the right place (ie in /images/ from public-root) then the script should work. Also assuming your input-file form field is named 'files'.

You could try adding
touch(UploadDir . $_FILES['files']['name']);
prior to the move_uploaded_file line and see if you get a different error return.
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 10-17-2002, 01:23 PM   PM User | #5
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
One more question...

Is your administration panel running from the same server as the main site?

You have addproduct.php in /home/holidays/public_html/admin
and the images will be in /var/www/images/uploads/
which sort of indicates they are different servers.
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 10-17-2002, 09:01 PM   PM User | #6
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi Okii and thanks for your replies. Have edited my post as suggested

As far as I'm aware the administration panel is running from the same server as the main site but how do I tell? Where on earth does /var/www/ come from? I have never seen this until the error message.

Thanks again, Sheryll.
sticks is offline   Reply With Quote
Old 10-17-2002, 09:10 PM   PM User | #7
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi again.

The input form field is name files.

I added the extra line and tested again - now get this error message:-

Warning: unable to create file /var/www/images/uploads/jamesdean.jpg because No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 316

Warning: Unable to create '/var/www/images/uploads/jamesdean.jpg': No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 317

Warning: Unable to move '/tmp/phpAhZKmv' to '/var/www/images/uploads/jamesdean.jpg' in /home/holidays/public_html/admin/addproduct.php on line 317
product added successfully

Is there anything else I should check?

Thanks, Sheryll.
sticks is offline   Reply With Quote
Old 10-18-2002, 01:23 AM   PM User | #8
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi again.

This newbie is trying to learn by reading all I can find and have found out that /var/www is the "document_root" after running a phpinfo file.

home/holidays/public_html etc is the path to where the html files are.

I'm confused about what I should do next.

Thanks, Sheryll.
sticks is offline   Reply With Quote
Old 10-18-2002, 01:30 AM   PM User | #9
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi again.
Have also learnt from phpinfo file that upload_tmp_dir has "no value". I thought the images were uploaded to a temporary directory so does this mean I have to make one and if so where would I do that?

Thanks, Sheryll.
sticks is offline   Reply With Quote
Old 10-18-2002, 06:41 PM   PM User | #10
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
Right - let's first try to get the script working by pulling out/amending the bits that do not work....

Firstly we need to find the top document that the server uses to parse addproduct.php. All this means is that if you had my_admin.php that then includes addproduct.php , the top document would be my_admin.php. If you actually have www.yourdoamin.com/admin/addproduct.php in the url then addproduct is the top document. Now, suss out which folder that document is in (eg addproduct.php would be in /admin/)

Once you've done that, create a new folder in that folder called 'test' and chmod it to 777 (might need ftp for that).

Now the 'get the script working' bit -
If we use relative linking to define the move_to directory within the script, we can easily target our new folder. This is to ensure the upload to /tmp/ bit is working properly.

Change
move_uploaded_file($_FILES['files']['tmp_name'], UploadDir . $_FILES['files']['name']);
to
move_uploaded_file($_FILES['files']['tmp_name'],'test/'.$_FILES['files']['name']);

and remove the touch() line now. All that did was try to create a blank file as a test.

If you can save the image using relative paths, you should be able to takes the few steps neccessary to get it into the proper folder.

Good luck Sheryll
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 10-20-2002, 02:09 AM   PM User | #11
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Okii - you're brilliant

Sorry for delay in replying but I've been away. Anyway I changed the script as per your instructions and guess what - no error messages
The images are up there sitting in the test folder. They are not actually showing up on the page when you choose a product from the database but I presume that's cos the path in that part of the script points to the old folder.
A white square box with red cross and no error messages is definately a step in the right direction.

Hope you don't mind telling me what to do next. Thanks again, Sheryll.
sticks is offline   Reply With Quote
Old 10-20-2002, 10:43 PM   PM User | #12
sticks
New Coder

 
Join Date: Oct 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
sticks is an unknown quantity at this point
Hi Okii.

I'm back
Have changed the path in addproduct.php and also in connect.php to /admin/images/uploads/ and now the pic not only uploads it shows up. Very happy here.

As the initial addproduct.php had UploadDir instead of the relative path I presume I now need to learn how to make it work this way. Also was wondering why it is done this way.

Thanks, Sheryll.
sticks is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:04 AM.


Advertisement
Log in to turn off these ads.