Jump to content

Upload file not working


lAZLf

Recommended Posts

So I have a script to upload two images and add information about them into a database. It doesn't seem to be working but I don't know why.

 

HTML:

			<form enctype="multipart/form-data" action="uploadimage.php" method="POST">	
		<table>
		<tr><td>title:</td><td><input type="text" name="title" /></td></tr>
		<tr><td>description:</td><td><textarea name="description" multiline="true" cols="50" rows="8" width="300px"></textarea></td></tr>

		<tr><td colspan="2">Choose a file to upload: <input name="uploadedfile" type="file" /></td></tr>
		<tr><td colspan="2">Choose another file to upload: <input name="uploadedfile2" type="file" /></td></tr>
		<tr><td colspan="2"><input type="submit" value="Upload File" /></td></tr>
		</table>
		</form>

 

 

PHP:

<?php
session_start();
include('dbconfig.php');
$date = date('g:iA M d, Y');

$target_path1 = "portimages/";
$target_path1 = $target_path1 . basename( $_FILES['uploadedfile']['name']); 

$target_path2 = "portimages/";
$target_path2 = $target_path2 . basename( $_FILES['uploadedfile2']['name']); 

if($_SESSION['level'] == 'admin') {
	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) && move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path2)) {
			mysql_query('INSERT INTO `portfolio images` (path, path2, date, title, description) VALUES ("/portimages/'.$_FILES['uploadedfile']['name'].'","/portimages/'.$_FILES['uploadedfile2']['name'].'","'.$date.'","'.$_POST['title'].'","'.$_POST['description'].'")') or die (mysql_error());

			echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
			" has been uploaded";
			header("Location: ".$_SERVER['HTTP_REFERER']);
	} else {
		echo "There was an error uploading the file, please try again!";
	}
} else {
	echo'please login with an admin account';
}

?>

 

 

ERROR MESSAGE:

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home4/annarbo1/public_html/svidler/uploadimage.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpl3c23c' to '' in /home4/annarbo1/public_html/svidler/uploadimage.php on line 13
There was an error uploading the file, please try again!

 

 

 

 

What's wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/190844-upload-file-not-working/
Share on other sites

PHP:

<?php
session_start();
include('dbconfig.php');
$date = date('g:iA M d, Y');

$target_path1 = "portimages/";
$target_path1 = $target_path1 . basename( $_FILES['uploadedfile']['name']); 

$target_path2 = "portimages/";
$target_path2 = $target_path2 . basename( $_FILES['uploadedfile2']['name']); 

if($_SESSION['level'] == 'admin') {
	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) && move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path2)) {
			mysql_query('INSERT INTO `portfolio images` (path, path2, date, title, description) VALUES ("/portimages/'.$_FILES['uploadedfile']['name'].'","/portimages/'.$_FILES['uploadedfile2']['name'].'","'.$date.'","'.$_POST['title'].'","'.$_POST['description'].'")') or die (mysql_error());

			echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
			" has been uploaded";
			header("Location: ".$_SERVER['HTTP_REFERER']);
	} else {
		echo "There was an error uploading the file, please try again!";
	}
} else {
	echo'please login with an admin account';
}

?>

 

 

ERROR MESSAGE:

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home4/annarbo1/public_html/svidler/uploadimage.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpl3c23c' to '' in /home4/annarbo1/public_html/svidler/uploadimage.php on line 13
There was an error uploading the file, please try again!

 

 

What's wrong with it?

 

Hey the only thing I see wrong with this code is that on this line here:

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)

Which is the first if (move_uploaded_file) check, the variable $target_path should be $target_path1. All you did was forget the 1 on the end.

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.