Solved

UPLOAD FILE PHP

Posted on 2007-04-05
17
1,089 Views
Last Modified: 2013-12-12
URGENT - pHP code to upload files

<?php
$target = "/photos/temp/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
0
Comment
Question by:MyDanes
  • 9
  • 4
  • 3
  • +1
17 Comments
 

Author Comment

by:MyDanes
ID: 18862008
woops the problem is:


Warning: move_uploaded_file(/photos/temp/ICOFormat-1.6f9-win.zip) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/positive/public_html/horses/photos/temp/upload.php on line 29

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php2pKnZK' to '/photos/temp/ICOFormat-1.6f9-win.zip' in /home/positive/public_html/horses/photos/temp/upload.php on line 29
Sorry, there was a problem uploading your file.
0
 

Author Comment

by:MyDanes
ID: 18862011
I have made sure that the directory /photos/temp exists (this is the directory where my upload.php lives)  PLEASE help
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18862921
change $target = "/photos/temp/";

to

$target = "./";
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:ilava
ID: 18863772

do u have photos/temp/ICOFormat-1.6f9-win.zip file in your location
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865037
try changing this

echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";

to

echo "The file ".
basename( $_FILES['uploaded']['name']). " has been uploaded";

kiranvj
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865050

and where do you assign values to $uploaded_size and $uploaded_type

kiranvj
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865078
to find the file size try this

$uploaded_size = $_FILES['uploaded']['size'];

to get the file type try

$uploaded_type = $_FILES['uploaded']['type'];


hope these helps
kiranvj
0
 

Author Comment

by:MyDanes
ID: 18865295
Kiranv,

echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";

to

echo "The file ".
basename( $_FILES['uploaded']['name']). " has been uploaded";

I don't see a difference in this change?
Also, I got this code from about.com tutorial - I am trying to just get something 'simple' for a user (NOT ME) to upload photos and am FAILING.  THANK YOU

0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865312
the difference is here $_FILES['uploaded']['name']

what is the name of the File control in html, uploaded or uploadedfile
and did you try $uploaded_size and $uploaded_type.

If possible give the link of the page in about.com

kiranvj
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865352
also try this

$target = "/photos/temp/";

chmod($target,0755); // this is to set the permissions

$target = $target . basename( $_FILES['uploaded']['name']) ;


kiranvj
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18865363
where is your php file located? is it in public_html OR horses OR photos OR temp
0
 

Author Comment

by:MyDanes
ID: 18868440
I put the .php in the temp folder where I wanted the files to land
0
 
LVL 16

Accepted Solution

by:
Kiran Paul VJ earned 500 total points
ID: 18868524
then use this

$target = "";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;


or

// $target = "/photos/temp/"; // this line is not needed since ur php file is in temp dir
$target = basename( $_FILES['uploaded']['name']) ;
$ok=1;
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18868560
LOL this is unbelievable 1 day and 10 posts later and you come back to my original sugestion.

LOLLL
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18869864
how come $target = "./"; and $target = ""; are same.

please clarify
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 18869872
and i think the poster dont mind to check ur suggestion
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18869946
. is the current directory
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question