Setting the directory to upload an image php

This is a discussion on "Setting the directory to upload an image php" within the PHP Forum section. This forum, and the thread "Setting the directory to upload an image php are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 10th, 2006, 21:13
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Setting the directory to upload an image php

Hi, I have a problem with this php script to upload an image, I did this after reading about 100 tutorials.

It seems to get all of the information but im wondering if ive set the directory wrong. Heres the code


<?php
$error_message = ""; //error upload message, set to zero
$Image_file = $_FILES[upload_file][name]; //the orignal/extension $Image_size = $_FILES[upload_file][size]; //the size of the image
$Image_type = $_FILES[upload_file][type]; //the type of the image
$Temp_directory = $_FILES['upload_file']['tmp_name']; //the temp directory
$Target_directory = "web/Image/"; //the target directory (IS THIS RIGHT?)
$Target_directory = $Target_directory . basename( $_FILES['upload_file']['name']); //the target i.e. web/Image/picture1.jpg

// just checks that the correct information is being sent
echo "The name of the file from the form is $Image_file <br>";
echo "The size of the image is $Image_size <br>";
echo "The type of file uploaded is $Image_type <br>";
echo "The temporary path is $Temp_directory <br>";
echo "The target path is $Target_directory <br>";
echo "File being copied is $Temp_directory to $Target_directory";

//checks file is a picture and is not greater than around 100000kb
if ( !ereg( "gif|png|x-png|jpeg", $_FILES[upload_file][type]) ) {
echo "This is not an image";
}
else if ( $_FILES[upload_file][size] > 110000 ) {
echo "This file is too large";
}

//I believe this is what I need to copy the file - I wrote this using the php.net help so I assume its right

if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $Target_directory)) {
echo "File was uploaded";
} else {
echo "File was not uploaded";
}



Now the problem that im getting is its outputting "File was not uploaded" (plus obviously the echo statements at the top)

Ive set the chmod of the directory Image to 777. And im assuming ive made an error in either the directory,

My ROOT directory is web and the directory i want to upload to is Image, do I need
$Target_directory = /web/Image or = web/Image or /web/Image/ or web/Image/ - I think its /web/Image/
Do I need to add the filename onto this - in my code i have set it to be whatever the original file name was.

If its not this then I assume it must be the move() statement, should the parameters for these be
move(temporary_path, target_path) where
temporary_path = "/tmp/temporary-file-name" and
target_path = "/www/Image/original-file-name

Any help on this would be greatly appreciated as I would have liked to have got something working tonight. Thanks
Reply With Quote

  #2 (permalink)  
Old Jan 11th, 2006, 09:35
New Member
Join Date: Jan 2006
Location: Netherland
Age: 37
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting the directory to upload an image php

Hello,

I see you get in trouble with you php upload,
I suggest to use an existing PHP class, try this one: http://www.finalwebsites.com/snippets.php?id=7

regards Olaf
Reply With Quote
  #3 (permalink)  
Old Jan 11th, 2006, 15:39
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting the directory to upload an image php

Hi, thanks for the reply but I was hoping to do it myself. Ive sorted it now, it looks like it was down to setting the wrong directory. I used this and put the upload script into the directory I wanted to upload images to and it seems to work (used copy() instead of move() as well)


PHP: Select all

copy ($_FILES['upload_file']['tmp_name'], $_FILES['upload_file']['name']) or die ('Could not upload'); 

At the moment ive got this directory set to chmod 777, from reading what people have said in other threads this is dangerous and it places you at the mercy of malicious users - would you know of an alternative to using this setting, thanks.
Reply With Quote
Reply

Tags
setting, directory, upload, image, php

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to view an image to the upload directory? lyndon PHP Forum 5 Nov 12th, 2007 04:27
Setting a default image size using CSS? Inkers Web Page Design 4 Oct 12th, 2007 15:10
Example of Image Upload hanusoft Classic ASP 1 Sep 20th, 2007 10:39
Repeating an image along the bottom of the page without setting it as background. imagius Web Page Design 9 Apr 27th, 2007 08:35
Setting IIS for scripts in main website directory Webforumz Staff Classic ASP 9 Jun 30th, 2004 08:55


All times are GMT. The time now is 07:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43