473,382 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Does my localhost have a build in temporary file to store images?

Hello everyone:

i been trying to write a php script to upload an image to my file within my root file localhost/gw. so then i could display it on a different page, but the book i'm learning from say the image will first upload to a tmp file on the localhost, however, i could not find this tmp file they are talking about,or even where the image go after i click add or submit. so do i have to crate a tmp file, and let the image first store in? i already write the command on php to redirect the file from tmp

Expand|Select|Wrap|Line Numbers
  1.  
  2.     $target=gw_uploadpath.$screenshot;
  3.     if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){
  4.  
Mar 15 '11 #1
8 2817
dgreenhouse
250 Expert 100+
The temp file is created automatically via the files post.

See: http://php.net/manual/en/features.fi...ost-method.php
Mar 15 '11 #2
cool, is there anyway i could locate this temporary file? or is it hidden? because i keep trying to find it but i can't seem to find it at all. and did i use the command correctly? or is there any other better way to move it? cos from my understanding is the command move the uploaded file to tempoary file then from temp move it to the file i crated, am i right? thank you by the way dgreenhous
Mar 15 '11 #3
dgreenhouse
250 Expert 100+
Edit: I just modified an example from the PHP man and might have confused the issue with my earlier post...

use:
ini_get("upload_tmp_dir"); // to get the temp upload dir

You need to do it the way noted in the link.
The temp file disappears from the temp dir when the script finishes.
That's why you have to move it.

Here's a simple modification of the example from the PHP man:
Expand|Select|Wrap|Line Numbers
  1. <!-- HTML fragment
  2.   The data encoding type, enctype, MUST be specified as below -->
  3. <form enctype="multipart/form-data" action="upload.php" method="POST">
  4.     <!-- MAX_FILE_SIZE must precede the file input field -->
  5.     <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
  6.     <!-- Name of input element determines name in $_FILES array -->
  7.     Send this file: <input name="userfile" type="file" />
  8.     <input type="submit" value="Send File" />
  9. </form>
  10.  
Expand|Select|Wrap|Line Numbers
  1. // file: upload.php
  2. $uploaddir = ini_get("upload_tmp_dir") . "/" ;
  3. echo $uploadfile; // Just see the temp dir
  4.  
  5. $target = gw_uploadpath.$screenshot;
  6. /* or
  7. $target = gw_uploadpath.basename($_FILES['userfile']['name'])
  8.  
  9. I assume gw_uploadpath is a constant
  10. */
  11.  
  12. echo '<pre>';
  13.  
  14. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) {
  15.     echo "File is valid, and was successfully uploaded.\n";
  16. } else {
  17.     echo "Possible file upload attack!\n";
  18. }
  19.  
  20. echo 'Here is some more debugging info:';
  21.  
  22. print_r($_FILES); // See the $_FILES array
  23.  
  24. print "</pre>";
  25.  
Mar 16 '11 #4
<?php
define('guitar_uploadpath','images/');

if(isset($_POST['submit'])){

//get score data from the post
$name=$_POST['name'];
$score=$_POST['score'];
$screenshot=$_FILES['screenshot']['name'];

if(!empty($name)&&!empty($score)&&!empty($screensh ot)){
$target=guitar_uploadpath.$screenshot;
if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){

$dbc=mysqli_connect('','','','guitar')
or die('Error connect database');

$query="insert into guitarwars values (0, now(), '$name', '$score', '$screenshot')";
mysqli_query($dbc, $query)
or die('error querying');

echo'<p>Thanks for adding your new high score!</p>';
echo'<p><strong>Name:</strong>'.$name.'<br/>';
echo'<strong>Score:</strong>'.$score.'</p>';
echo'<img src="'.guitar_uploadpath.$screenshot.'" alt="Score image"/></p>';
echo'<p><a href="index.php">&lt;&lt; Back to high scores</a></p>';

$name="";
$score="";

mysqli_close($dbc);
}

else{
echo'<p class="error">Please enter all of the infor to add your score.</p>';
}
}
}
?>

<h2>Guitar Wars - Add Your Score</h2>

<hr/>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['php_self'];?>">
<input type="hidden" name="max_file_size" value="32768"/>
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name;?>"/><br/>
<label for="score">Score:</label>
<input type="text" id="score" name="score" value="<?php if(!empty($score)) echo $score;?>"/><br/>
<label for="screenshot">Screen Shot:</label>
<input type="file" id="screenshot" name="screenshot"/><hr/>
<input type="submit" value="add" name="submit"/>
</form>

</body>
</html>
Apr 18 '11 #5
here is my add score php, ok so after i try it again and read your respond i stil have this few problem, first after i type in name score and select an image after clicking submit my echo message come out saying that i need to input all information, but when the message come out the file field where the image go is empty again. i chose some randome jpg image just to text it out. and the gw_uploadpath is a constant i just read over again from the book i'm learning from. by the way do i have to crate an images folder under my web folder thats inside of localhost? oh sorry about the very last respond, thank you again greenhouse
Apr 18 '11 #6
and one more thing what ini_get do different from move_uploaded_file?
Apr 18 '11 #7
hello another question lol, in the guitar_uploadpath would this be a folder thats under my web folder? and if it is do i crate one folder under my web folder name guitar uploadpath?
Apr 18 '11 #8
(!empty($name)&&!empty($score)&&!empty($screensh ot)){
$target=guitar_uploadpath.$screenshot;
if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){

$dbc=mysqli_connect('','','','guitar')
or die('Error connect database');

$query="insert into guitarwars values (0, now(), '$name', '$score', '$screenshot')";
mysqli_query($dbc, $query)
or die('error querying');

echo'<p>Thanks for adding your new high score!</p>';
echo'<p><strong>Name:</strong>'.$name.'<br/>';
echo'<strong>Score:</strong>'.$score.'</p>';
echo'<img src="'.guitar_uploadpath.$screenshot.'" alt="Score image"/></p>';
echo'<p><a href="index.php">&lt;&lt; Back to high scores</a></p>';

$name="";
$score="";

mysqli_close($dbc);
}

else{
echo'<p class="error">Please enter all of the infor to add your score.</p>';

here is my problem why is it after !empty($screenshot) and i input an image but the echo still come up as enter all information?
Apr 18 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cover | last post by:
The question is, we have two options to store images, either in a Database (MySQL, Postgres, ...) like blob data, or in the hard disk the file and the path in database. Which option is better?...
5
by: Jason Charalambides | last post by:
I set a program to automatically load values from a temporary file. However, there is a chance that the specific temporary file "C:\Temp\TU.tmp" may not exist at all. In that case I want that...
4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
1
by: db | last post by:
How can I store images in a dataset? I have a column 'Thumbnail' with object as datatype, but how do I store the images there? db
6
by: Codemonkey | last post by:
Hi, I have a few questions about best practices when it comes to the management of temporary files. Any thoughts anyone can give would be much appreciated. Basically, I'm writing a document...
4
by: lwoods | last post by:
I need to create a temporary file on a server. How do I do it? I tried using IO.Path but it created a local file; i.e., file://C:...... TIA, lwoods
1
by: pcosway | last post by:
Core question: where does MySQL create temporary files in a quick rebuild? ( I thought I knew the answer, but now can't find them.) I'm trying to rebuild a file using "repair table...
1
by: nwebhosting | last post by:
Hello and thank you. Could you please help me with this.: i try to store images using the following code, and it just bring a blank screen. i being trying different things and i am not sure if...
9
bilibytes
by: bilibytes | last post by:
Hi, i am wondering how did a website like facebook, myspace or whatever social networking site store their images? do they store them in a DB or roughly like files? thankyou in advance and ...
0
by: krike | last post by:
Hey all first of all I'm new :D so hy my question is regarding the temporary file, I'm running 2 CMS systems on my xampp local server, the first is called PHP-nuke and the second is Nuke...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.