Solved

UPLOAD FILE PHP

Posted on 2007-04-05
17
1,080 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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:kiranvj
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:kiranvj
ID: 18865050

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

kiranvj
0
 
LVL 16

Expert Comment

by:kiranvj
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:kiranvj
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:kiranvj
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:kiranvj
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:
kiranvj 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:kiranvj
ID: 18869864
how come $target = "./"; and $target = ""; are same.

please clarify
0
 
LVL 16

Expert Comment

by:kiranvj
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.

829 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