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.
|
|
|
|
|
![]() |
||
Setting the directory to upload an image php
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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 |
|
|
|
|||
|
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 |
|
|||
|
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)
|
![]() |
| Tags |
| setting, directory, upload, image, php |
| Thread Tools | |
|
|
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 |