我写了以下代码。 Web浏览器中没有写入任何内容,也不会引发任何错误。 谁能帮助我找出问题所在?
try { echo file_get_contents($_FILES["image"]["tmp_name"]); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }这是表格:
echo "<form action='upload.php' method='post' enctype='multipart/form-data'> <p><input type='file' name='myfile'/></p> <p><input type='submit' value='Upload'/></p> </form>";问题是我正在按照我应该设置的教程:$ image = file_get_contents($ _ FILES [“image”] [“tmp_name”]); 当教程中的人试图回应它时,文件内容是在浏览器中写入的。 我什么都没发生。 我认为它不起作用。
I have written the following code. Nothing is written in the web browser and no error is thrown. Can anyone please help me to identify the problem?
try { echo file_get_contents($_FILES["image"]["tmp_name"]); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }Here is the form:
echo "<form action='upload.php' method='post' enctype='multipart/form-data'> <p><input type='file' name='myfile'/></p> <p><input type='submit' value='Upload'/></p> </form>";The thing was that I was following a tutorial where I was supposed to set: $image=file_get_contents($_FILES["image"]["tmp_name"]); When the person in the tutorial tried to echo it the files content was written in the browser. Nothing happened for me. I assume it is not working.
最满意答案
使用
file_get_contents($_FILES["myfile"]["tmp_name"]);代替
file_get_contents($_FILES["image"]["tmp_name"]);since <input type='file' name='myfile'/>
更好的引用更改通过表单上传的tmp文件的文件名
if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id) && isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK') { $name = basename($_FILES['myfile']['name']); $ext = end(explode('.', $name)); $info = getimagesize($_FILES['myfile']['tmp_name']); }use
file_get_contents($_FILES["myfile"]["tmp_name"]);instead of
file_get_contents($_FILES["image"]["tmp_name"]);since <input type='file' name='myfile'/>
better ref from Changing the file name of a tmp file uploaded through a form
if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id) && isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK') { $name = basename($_FILES['myfile']['name']); $ext = end(explode('.', $name)); $info = getimagesize($_FILES['myfile']['tmp_name']); }echo file_get_contents($ _ FILES [“image”] [“tmp_name”]不执行任何操作(echo file_get_contents($_FILES[“image”][“tmp_name”] doesn't do anything)我写了以下代码。 Web浏览器中没有写入任何内容,也不会引发任何错误。 谁能帮助我找出问题所在?
try { echo file_get_contents($_FILES["image"]["tmp_name"]); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }这是表格:
echo "<form action='upload.php' method='post' enctype='multipart/form-data'> <p><input type='file' name='myfile'/></p> <p><input type='submit' value='Upload'/></p> </form>";问题是我正在按照我应该设置的教程:$ image = file_get_contents($ _ FILES [“image”] [“tmp_name”]); 当教程中的人试图回应它时,文件内容是在浏览器中写入的。 我什么都没发生。 我认为它不起作用。
I have written the following code. Nothing is written in the web browser and no error is thrown. Can anyone please help me to identify the problem?
try { echo file_get_contents($_FILES["image"]["tmp_name"]); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }Here is the form:
echo "<form action='upload.php' method='post' enctype='multipart/form-data'> <p><input type='file' name='myfile'/></p> <p><input type='submit' value='Upload'/></p> </form>";The thing was that I was following a tutorial where I was supposed to set: $image=file_get_contents($_FILES["image"]["tmp_name"]); When the person in the tutorial tried to echo it the files content was written in the browser. Nothing happened for me. I assume it is not working.
最满意答案
使用
file_get_contents($_FILES["myfile"]["tmp_name"]);代替
file_get_contents($_FILES["image"]["tmp_name"]);since <input type='file' name='myfile'/>
更好的引用更改通过表单上传的tmp文件的文件名
if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id) && isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK') { $name = basename($_FILES['myfile']['name']); $ext = end(explode('.', $name)); $info = getimagesize($_FILES['myfile']['tmp_name']); }use
file_get_contents($_FILES["myfile"]["tmp_name"]);instead of
file_get_contents($_FILES["image"]["tmp_name"]);since <input type='file' name='myfile'/>
better ref from Changing the file name of a tmp file uploaded through a form
if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id) && isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK') { $name = basename($_FILES['myfile']['name']); $ext = end(explode('.', $name)); $info = getimagesize($_FILES['myfile']['tmp_name']); }
发布评论