Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.