Solved

UPLOAD FILE PHP

Posted on 2007-04-05
17
1,103 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

627 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