Solved

UPLOAD FILE PHP

Posted on 2007-04-05
17
1,067 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
Comment Utility
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
Comment Utility
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
Comment Utility
change $target = "/photos/temp/";

to

$target = "./";
0
 
LVL 3

Expert Comment

by:ilava
Comment Utility

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

Expert Comment

by:kiranvj
Comment Utility
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:kiranvj
Comment Utility

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

kiranvj
0
 
LVL 16

Expert Comment

by:kiranvj
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 16

Expert Comment

by:kiranvj
Comment Utility
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:kiranvj
Comment Utility
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:kiranvj
Comment Utility
where is your php file located? is it in public_html OR horses OR photos OR temp
0
 

Author Comment

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

Accepted Solution

by:
kiranvj earned 500 total points
Comment Utility
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
Comment Utility
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:kiranvj
Comment Utility
how come $target = "./"; and $target = ""; are same.

please clarify
0
 
LVL 16

Expert Comment

by:kiranvj
Comment Utility
and i think the poster dont mind to check ur suggestion
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
. is the current directory
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now