PDA

View Full Version : An easy upload script?



alexjewell
11-27-2007, 11:48 AM
I've poured over some books and websites hoping for a simple solution, but all of the scripts and ideas I've seen are simply too complicated. I'm hoping you guys can at least get me to the starting line of the right race so I can figure this thing out - I have deadlines and anxious clients and time is of the essence.

The client is an artist and I have a CMS where he can go in and upload an image and a for that image. Let's say the form is on upload.php and the images are in the directories below it: imgs/gallery/ for the full images and imgs/gallery/t/ for the s. How do I get from point A to point B - from the upload form to those directories with the images? And to put an individual image from the file input to a different directory depending on if that input's name is "file" or "thumb"?

Thanks for any help you can give me, I'm quite desperate at the moment - this project really needs to get done.

BLiZZaRD
11-27-2007, 01:55 PM
Does it have to be that way? Why not look into a photo gallery system.

One like Gallery (http://gallery.menalto.com/) is great, and you can configure it to your needs, it also has themes and skins and lots of other things, including carts and download options. When you upload the large image it will automatically make a thumbnail, which is displayed on the gallery page(s) and when clicked shows the larger image.

andersmoen
11-27-2007, 02:31 PM
http://www.w3schools.com/php/php_file_upload.asp

shriniwas
12-28-2007, 03:57 AM
Hi,
Got a working code from the link above :)
I'm using this code for file upload.... ;)
its fine with images but how can i upload other formats such as Microsoft Word or Exel file or any simple text file

Can anyone help me ?? :confused:



<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if

(file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>



Thanks in advence ......

codeexploiter
12-28-2007, 04:09 AM
Hello Shriniwas,

There is no point in posting your same question in multiple threads. I've already made a reply to your question in another thread which you can find at

http://www.dynamicdrive.com/forums/showthread.php?t=26379