Jump to content

[SOLVED] File upload


shergold

Recommended Posts

Hey, can anyone please help me with the following code, it just outputs a blank page each time i execute the page.

 

<?php
include("config.inc.php");
session_start();
if (!isset($_SESSION['user'])){
header("location: login.php");
exit();
}

//filepath
$filename = $_FILES['file']['name'];
$code = rand(5,5);
$newname = $filename . $code;
$link = "<a href=\"localhost/image.php?loc=$newname\"";
$targetpath = "/imageup";
$targetpath = $targetpath .  basename($newname);

//file restrictions	
if (
$_FILES['file']['type'] == "image/jpg"
|| $_FILES['file']['type'] == "image/gif"
|| $_FILES['file']['type'] == "image/jpeg"
&& $_FILES['file']['size'] < 1048576
)
{
if($_FILES['file']['error'] > 1)
	{
	exit ("<center>There has been an error uploading your file:" . $_FILES['file']['error'] . "</center><br />");
	}
	elseif (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath))
	{
	echo "Your file has been succesfully uploaded <br />";
	echo "<div class=\"upload_info\" align=\"center\">";
	echo "<center>File uploaded: " . $_FILES['file']['name'] . "<br />";
	echo "File type: " . $_FILES['file']['type'];
	echo "File size: " . $_FILES['file']['size'];
	echo "Storage location: " . "<a href=\"localhost/image.php?loc=" . uniqid() . "\"</a>";
	echo "expiry date: ";
	echo "</div>";
	}

}
else
echo "<center><b>Invalid file</b></center>";




?>

 

Thanks,

shergold.

Link to comment
https://forums.phpfreaks.com/topic/166046-solved-file-upload/
Share on other sites

Are you sure you want:

 

elseif (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath))
	{
	echo "Your file has been succesfully uploaded <br />";

 

I would try:

 

else
	{
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath));
	echo "Your file has been succesfully uploaded <br />";

 

Also, your final else statement is missing the brackets - change it to:

 

else
{
echo "<center><b>Invalid file</b></center>";
}

Link to comment
https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875762
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.