Solved

UPLOAD FILE PHP

Posted on 2007-04-05
17
1,096 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

738 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