I'd like some help for the upload photos
For ch9
I tried to upload a jpeg
I use win8.1
Notice: Undefined index: photo in C:\xampp\htdocs\photo\photo_upload.php on line 34
Sorry, there was a problem uploading that photo. Please contact your server administrator for help.
i typed attrib c:\<path>\..\.\photos to try to deselect read only
If someone made it work I'd really like to make it work
heres the code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Process Photo Upload</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<?php
if ( isset( $_POST["sendPhoto"] ) ) {
processForm();
} else {
displayForm();
}
function processForm() {
if ( isset( $_FILES["photo"] ) and $_FILES["photo"]["error"] == UPLOAD_ERR_OK ) {
if ( $_FILES["photo"]["type"] != "image/jpeg" ) {
echo "<p>JPEG photos only, thanks!</p>";
} elseif ( !move_uploaded_file( $_FILES["photo"]["tmp_name"],
"photos/" . basename( $_FILES["photo"]["name"] ) ) ) {
echo "<p>Sorry, there was a problem uploading that photo.</p>" .
$_FILES["photo"]["error"] ;
} else {
displayThanks();
}
} else {
switch( $_FILES["photo"]["error"] ) {
case UPLOAD_ERR_INI_SIZE:
$message = "The photo is larger than the server allows.";
break;
case UPLOAD_ERR_FORM_SIZE:
$message = "The photo is larger than the script allows.";
break;
case UPLOAD_ERR_NO_FILE:
$message = "No file was uploaded. Make sure you choose a file to upload.";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = "PHP doesn â t have access to a temporary folder on the server to store the file.";
break;
case UPLOAD_ERR_CANT_WRITE:
$message = "The file couldn't be written ti the server's hard disk for some reason.";
break;
case UPLOAD_ERR_EXTENSION:
$message = "The file upload was stopped by one of the currently loaded PHP extensions.";
break;
default:
$message = "Please contact your server administrator for help.";
}
echo "<p>Sorry, there was a problem uploading that photo. $message</p>";
}
}
function displayForm() {
?>
<h1>Uploading a Photo</h1>
<p>Please enter your name and choose a photo to upload, then click
Send Photo.</p>
<form action="photo_upload.php" method="post" enctype="multipart/
form-data">
<div style="width: 30em;">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<label for="visitorName">Your name</label>
<input type="text" name="visitorName" id="visitorName" value="" />
<label for="photo">Your photo</label>
<input type="file" name="photo" id="photo" value="" />
<div style="clear: both;">
<input type="submit" name="sendPhoto" id="sendPhoto" value="Send Photo" />
</div>
</div>
</form>
<?php
}
function displayThanks() {
?>
<h1>Thank You</h1>
<p>Thanks for uploading your photo<?php if ( $_POST["visitorName"] )
echo ", " . $_POST["visitorName"] ?>!</p>
<p>Hereâs your photo:</p>
<p><img src="photo/<?php echo $_FILES["photo"]["name"] ?>" alt="Photo" /></p>
<?php
}
?>
</body>
</html>
|